In process hosting is not supported error for ASPNetCoreModule in Azure DevOps pipeline

Problem

I recently encountered an error in Azure DevOps pipeline when I try to publish the newly upgraded .NET core application. I upgraded the application from .Net core 2.1 to .NET core 3.1. The error stated…


C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: The "TransformWebConfig" task failed unexpectedly. [C:\Dev\MyTigerApp\MyTigerApp.csproj]
C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: System.Exception: In process hosting is not supported for AspNetCoreModule. Change the AspNetCoreModule to at least AspNetCoreModuleV2. [C:\Dev\MyTigerApp\MyTigerApp.csproj]
C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.SetAspNetCoreHostingModel(String aspNetCoreHostingModelValue, String aspNetCoreModuleName, XElement aspNetCoreElement) [C:\Dev\MyTigerApp\MyTigerApp.csproj]
C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.TransformAspNetCore(XElement aspNetCoreElement, String appName, Boolean configureForAzure, Boolean useAppHost, String extension, String aspNetCoreModuleName, String aspNetCoreHostingModelValue, String projectFullPath) [C:\Dev\MyTigerApp\MyTigerApp.csproj]
C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.Transform(XDocument webConfig, String appName, Boolean configureForAzure, Boolean useAppHost, String extension, String aspNetCoreModuleName, String aspNetCoreHostingModel, String environmentName, String projectFullPath) [C:\Dev\MyTigerApp\MyTigerApp.csproj]
C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at Microsoft.NET.Sdk.Publish.Tasks.TransformWebConfig.Execute() [C:\Dev\MyTigerApp\MyTigerApp.csproj]
C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Dev\MyTigerApp\MyTigerApp.csproj]
C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\Dev\MyTigerApp\MyTigerApp.csproj]

Investigation

I then tried to publish the app manually using the following command and got the same error.


dotnet publish MyTigerApp.csproj --configuration Release --output C:\temp

This concluded that the error was not related to Azure DevOps but related to my project itself.

Solution

This can be fixed by changing the Web.Cofig from


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
  </system.webServer>
</configuration>

to


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
  </system.webServer>
</configuration>

Note that I have marked the modules as AspNetCoreModuleV2

Leave a Reply

Scroll to Top

Discover more from Cloudopian

Subscribe now to keep reading and get access to the full archive.

Continue reading