18

I am trying to publish asp.net core 2.1 application to azure app service through visual studio and getting following exception. How to resolve this?

C:\Program Files\dotnet\sdk\2.2.108\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(49,5): 
Error MSB4018: The "TransformWebConfig" task failed unexpectedly.
System.Exception: In process hosting is not supported for AspNetCoreModule. Change the AspNetCoreModule to atleast AspNetCoreModuleV2.
   at Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.TransformAspNetCore(XElement aspNetCoreElement, String appName, Boolean configureForAzure, Boolean useAppHost, String extension, String aspNetCoreModuleName, String aspNetCoreHostingModel)
   at Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.Transform(XDocument webConfig, String appName, Boolean configureForAzure, Boolean useAppHost, String extension, String aspNetCoreModuleName, String aspNetCoreHostingModel, String environmentName)
   at Microsoft.NET.Sdk.Publish.Tasks.TransformWebConfig.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

Solution:

Removing <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> from .csproj resolved my issue.

Mahbubur Rahman
  • 4,961
  • 2
  • 39
  • 46

2 Answers2

30

Add this line to your web.config:

<handlers>
  <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>

Or add this property in .csproj file.

<AspNetCoreModuleName>AspNetCoreModuleV2</AspNetCoreModuleName>

Update:

Removing <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> from .csproj resolve my issue.

Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • 1
    Adding `AspNetCoreModuleName>AspNetCoreModuleV2` to .csproj creates dependency error. But removing `InProcess` from .csproj resolve my issue. – Mahbubur Rahman Oct 24 '19 at 09:03
  • The webconfig part helped me. I copied some source code, including a reference to "AspNetCoreModule" (v1) from a different snippet. – Anoni2 Jan 05 '22 at 23:49
  • Specifying AspNetCoreModuleV2 solved my problem. – peter70 Mar 02 '23 at 06:39
3

To get rid of this error, I disabled the web config transform by setting the IsTransformWebConfigDisabled property to true in my csproj file. A web.config file is useless when using Kestrel on macOS anyway, not sure why the build system tries to transform a non-existent web.config file on macOS in the first place.

<PropertyGroup>
  <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
0xced
  • 25,219
  • 10
  • 103
  • 255