43

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ı ==========
AskYous
  • 4,332
  • 9
  • 46
  • 82
Kellad
  • 618
  • 1
  • 5
  • 10
  • 1
    Show us your web.config. – Ian Kemp Dec 27 '18 at 10:44
  • it it empty: – Kellad Dec 27 '18 at 11:45
  • It's a known bug: https://github.com/aspnet/websdk/issues/437 that they have fixed (even though it's not marked as such), but the fix might not be released yet. I'd suggest you switch to a non-Preview version of the .NET Core SDK (current stable version is 2.2.101). – Ian Kemp Dec 27 '18 at 15:05
  • Thank you. But I get the same error on 2.2.101 version. How can I apply this fix to my environment? As I see this error only occurs on Turkish machines. – Kellad Dec 31 '18 at 18:27
  • 2
    Just remove the `Web.Config` file from our project, that is what is causing the issue and you don't really need that. – Alexz S. Apr 30 '20 at 14:42

11 Answers11

65

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://learn.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>
Andy Raddatz
  • 2,792
  • 1
  • 27
  • 29
54

I had the same problem and found the solution

In the csproj file, find following line and delete.

<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
static_cast
  • 1,174
  • 1
  • 15
  • 21
Barış Bar
  • 562
  • 5
  • 4
34

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

<AspNetCoreHostingModelV2>InProcess</AspNetCoreHostingModelV2>

Note the V2 addition.

R. van Diesen
  • 829
  • 8
  • 10
  • 2
    While this seems to work, it will probably have to change for .NET Core 3 as well. It is likely that your Web.config file was generated with this handler that would make this redundant I think: ``. Either works. – Kody Aug 06 '19 at 17:01
  • @Kody your answer is the correct one! (at least for me) – sabotero Oct 02 '19 at 09:51
  • 2
    AspNetCoreHostingModelV2 is meaningless, you could try AspNetCoreHostingModelV100 is ok. Simply just remove it. – nam vo Apr 10 '20 at 03:45
  • 2
    @namvo you have oped my eyes. I was actually thinking this issue has been fixed in V2 version but actually this property becomes unknown when you change it's name. Thank you. But I'm still looking for an answer what will be the impact of removing it? – Raza Jun 01 '20 at 18:45
15

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

Mhsn
  • 495
  • 4
  • 12
13

Just add this line to your web.config file

<handlers>
  <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
OIbuoye
  • 289
  • 4
  • 7
  • 1
    This was the one that worked for me. I had this line already but had to change `AspNetCoreModule` to `AspNetCoreModuleV2`. Using .NET Core 3.1 web api with a web.config for custom HTTP headers. – Dave Sep 22 '21 at 20:55
3

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.

Jamshaid K.
  • 3,555
  • 1
  • 27
  • 42
  • 1
    TFS-related issues like for me was the accidentally engaged web.config file in tfs and after checking in, the file was read-only and caused problem. I checked it out and excluded it from the project and that worked. @Jamshaid K. Thanks very much for the hint. – Sherveeen Feb 28 '23 at 15:05
2

I had a project in TFS, due to some issues, the TFS went down and when I made it go online again, it failed to publish the project, while the debugging worked fine. It caused the error (The TransformWebConfig task failed unexpectedly).

After checking the output window, it seemed some files were not accessible to visual studio, or were protected. So, it was because of the TFS, all or most of the files in the project were set as Read-Only which is why Visual Studio couldn't transform those files.

Removing the Read-Only flag from the project fixed the publishing problem.

Jamshaid K.
  • 3,555
  • 1
  • 27
  • 42
1

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>

0

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

to this

<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

M.Qassem
  • 201
  • 2
  • 3
0

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

<PropertyGroup>
  <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
JrBriones
  • 93
  • 1
  • 5
0

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

The 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.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Ponvel
  • 1
  • 1