The "TransformWebConfig" task failed unexpectedly - System.Exception: The acceptable value for AspNetCoreModuleHostingModel property is either

Viewed 23557

I get

'The "TransformWebConfig" task failed unexpectedly. System.Exception: The acceptable value for AspNetCoreModuleHostingModel property is either "InProcess" or "OutOfProcess".'

error while publishing an ASP.NET Core 2.2.0 application (actually it is the included sample application) for win-x64 environment. Both Visual Studio 2017 and 2019 gives the same error. I am working on Windows 10. What should I do to solve this? Last part of publish Output is:

c:\users\engin\source\repos\NetCoreWebApplication2\NetCoreWebApplication2\obj\Release\netcoreapp2.2\win-x64\PubTmp\Out\
C:\Program Files\dotnet\sdk\2.2.200-preview-009648\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(49,5): Hata MSB4018: "TransformWebConfig" görevi beklenmedik biçimde başarısız oldu.
System.Exception: The acceptable value for AspNetCoreModuleHostingModel 
 property is either "InProcess" or "OutOfProcess".
   konum: Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.TransformAspNetCore(XElement aspNetCoreElement, String appName, Boolean configureForAzure, Boolean useAppHost, String extension, String aspNetCoreModuleName, String aspNetCoreHostingModel)
   konum: Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.Transform(XDocument webConfig, String appName, Boolean configureForAzure, Boolean useAppHost, String extension, String aspNetCoreModuleName, String aspNetCoreHostingModel, String environmentName)
   konum: Microsoft.NET.Sdk.Publish.Tasks.TransformWebConfig.Execute()
   konum: Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   konum: Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

2 Derleme başarısız oldu. Daha fazla ayrıntı için çıktı penceresini denetleyin.
========== Oluşturma: 1 başarılı, 0 başarısız, 0 güncel, 0 atlandı ==========
========== Yayın: 0 başarılı, 1 başarısız, 0 atlandı ==========
10 Answers

I would suggest disabling web.config transforms altogether. In an ASP.Net Core project you probably do not need to transform web.configs since supplying environment variables is handled by convention with appsettings.[Environment].json files.

From the docs at https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.2:

To prevent the Web SDK from transforming the web.config file, use the <IsTransformWebConfigDisabled> property in the .csproj file:

<PropertyGroup>
   <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>

I had the same problem and found the solution

In the csproj file, find following line and delete.

<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

Had the same issue on .net core 2.2.104. Update the section to this:

<AspNetCoreHostingModelV2>InProcess</AspNetCoreHostingModelV2>

Note the V2 addition.

The answer @Barış Bar provided is working but can cause future errors. There is a bug about UpperCases. Just change InProcess in csproj file with lowercase

<AspNetCoreHostingModel>inprocess</AspNetCoreHostingModel>

It is said that the bug will be corrected in VS 2019.

InProcess or OutOfProcess

Just add this line to your web.config file

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

My .NET Core 2.2 application build was failing on Jenkins but it was working fine on local machine. Error: error MSB4018: The "TransformWebConfig" task failed unexpectedly.

Fix: Removed below line from .csproj file <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

For me, there was a permission issue which is why, while publishing, a transformation task was running on web.config file. That file did not had access for normal user.

Closing Visual Studio and running it as Administrator then publishing the project worked for me or you can try on setting the correct permissions for the problematic file.

After successfully publishing the project once with administrator privileges, visual studio started working with normal users as well (weird though but good).


UPDATE:

Stumbled into the same problem again, and this time it was not resolved by the above solution, I had to check back the project directory and some of the files were marked Read-Only had to change it to get it working. I suppose this is a problem with the TFS which gets the files and sets them as Read-Only.

find the project file (.csproj) and update this code <AspNetCoreHostingModel>OutProcess</AspNetCoreHostingModel>

to this

<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

Adding this to the .csproj file did it for me:

<PropertyGroup>
  <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>

If you are upgrading your .net core version from 3.1 to higher framework, please check web.config aspNetCore node

attribute "hostingModel" should be "inprocess" (all small case) vs "InProcess" in .netcore 3.1 framework

this change worked for me and able to publish my project.

Related