Sdk: "TransformWebConfig" task could not be loaded

Created on 4 Apr 2017  ·  13Comments  ·  Source: dotnet/sdk

We experience this error when building new VS2017 csproj project with msbuild 2015:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(54,5): error MSB4062: The "TransformWebConfig" task could not be loaded from the assembly C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\..\..\tools\net46\\Microsoft.NET.Sdk.Publish.Tasks.dll. Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\tools\net46\Microsoft.NET.Sdk.Publish.Tasks.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. 

Also it seems some other people experience it as well. See https://github.com/Microsoft/msbuild/issues/1010 and http://stackoverflow.com/q/42805862/213725

Most helpful comment

@night-king - The log shows that you have an incorrect configuration setup. You cannot have inprocess hosting with AspNetCoreModule.

Can you add this to the csproj? This should fix the issue.

<AspNetCoreModuleName>AspNetCoreModuleV2</AspNetCoreModuleName>

All 13 comments

It may be the same reason for a special case, but same is true for Service Fabric's *.sfproj projects.

I am trying to build *.sfproj through MS Build 15.0 (15.1.548.43366) and get the same exception, the only difference seems to be that I am using the Enterprise version of Visual Studio 2017
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(54,5): Error MSB4062: The "TransformWebConfig" task could not be loaded from the assembly C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\..\..\tools\net46\\Microsoft.NET.Sdk.Publish.Tasks.dll. Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\tools\net46\Microsoft.NET.Sdk.Publish.Tasks.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

The actual command that is being executed seems to be the following:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\msbuild.exe "*.sfproj" /nologo /nr:false /fl /flp:"logfile=path\file.log" /dl:CentralLogger,"path\1.0.45\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=..|SolutionDir=.."*ForwardingLogger,"path\1.0.45\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /t:Package /p:PackageLocation=path /p:platform="x64" /p:configuration="Configuration" /p:VisualStudioVersion="15.0" /m /p:_MSDeployUserAgent="MyTFSAgent"

Am I doing something wrong here?

If you don't need to transform web.config in your ASP.NET Core application, a temporary workaround could be to comment out "TransformWebConfig" task and "_TransformWebConfig" target in Microsoft.NET.Sdk.Publish.TransformFiles.targets. Hopefully later there will be a proper resolution of this issue.

This probably needs to go into the websdk repo https://github.com/aspnet/websdk where those tasks / targets are coming from..
cc @vijayrkn

While looking through the different .target files I have noticed another issue: _PublishTaskAssemblyFullPath from the C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\Microsoft.NET.Sdk.Publish.targets file is set incorrectly, and that's why the path appears with two backslashes "\" in the error instead with a single backslash "". The fix probably would have to be simple, by removing the extra backslash "" from the following position inside the target file: (26,107). However this is not helping with the issue discussed here.

We just fixed this issue in websdk - https://github.com/aspnet/websdk/pull/174

Work-around:
Change msbuild path from C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\msbuild.exe to
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe

This issue should only happen when executing the 64 bit version of msbuild. Once the fix is rolled out, it should work for 64 bit as well. Until then, please use the msbuild under Binmsbuild.exe.

Closing since this has been addressed in the web sdk already.

Hey @vijayrkn,
I'm using VSTS hosted 2017 agent and trying to build my Service Fabric app. I'm getting same error. Any idea?

Thanks

This fix is only available in the 2.0 version of the cli. Can you check what version of dotnet cli is installed on the agent?

I have the same issue, where TransformwebConfig could not be loaded due to the error in path "\"
I am using vsts hosted agent as well.
How do I check the dotnet cli version of the hosted 2017 agent on vsts?

Based on https://www.visualstudio.com/en-us/docs/build/concepts/agents/hosted
the hosted agent has a set of available capabilities.

How do I work around this issue when I am using a hosted agent?

Answer:
Under the build solution sfproj task, user MSBuild x86

C:Program Filesdotnetsdk3.0.100-preview-009812SdksMicrosoft.NET.Sdk.Publishbuildnetstandard1.0TransformTargetsMicrosoft.NET.Sdk.Publish.TransformFiles.targets(49,5): 错误 MSB4018: “TransformWebConfig”任务意外失败。
System.Exception: In process hosting is not supported for AspNetCoreModule. Change the AspNetCoreModule to at least AspNetCoreModuleV2.
在 Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.TransformAspNetCore(XElement aspNetCoreElement, String appName, Boolean configureForAzure, Boolean useAppHost, String extension, String aspNetCoreModuleName, String aspNetCoreHostingModel)
在 Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.Transform(XDocument webConfig, String appName, Boolean configureForAzure, Boolean useAppHost, String extension, String aspNetCoreModuleName, String aspNetCoreHostingModel, String environmentName)
在 Microsoft.NET.Sdk.Publish.Tasks.TransformWebConfig.Execute()
在 Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
在 Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

@night-king - The log shows that you have an incorrect configuration setup. You cannot have inprocess hosting with AspNetCoreModule.

Can you add this to the csproj? This should fix the issue.

<AspNetCoreModuleName>AspNetCoreModuleV2</AspNetCoreModuleName>

I got similar issue as @night-king. "Error MSB4018: The "TransformWebConfig" task failed unexpectedly. System.Exception: In process hosting is not supported for AspNetCoreModule. Change the AspNetCoreModule to atleast AspNetCoreModuleV2."

My local builds fine. The issue only happened when I publish to azure.
Steps to resolve my issue:
1) as @vijayrkn mentioned, add the AspNetCoreModuleV2
2) save, close project, reopen project
3) get a new publish profile <--- after this step, publish works and the error went away

Was this page helpful?
0 / 5 - 0 ratings