2
votes

I am trying to create a build definition for an asp.net core application. My project compiles on the Visual Studio and also with MSBuild. When I am trying to run the solution on Azure to compile is where it fails to show the message below:

C:\Program Files\dotnet\sdk\2.2.105\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.<ExecuteInstantiatedTask>d__26.MoveNext()
Process 'msbuild.exe' exited with code '1'.

The weird thing is that I have currently installed on my computer the SDK 2.2.300 with Runtime 2.2.5, but when I am running the build definition in the VSTS it seems that the SDK it is using is 2.2.105. My initial thought was that the VSTS agent didn't have the correct version, and it was running with 2.2.105. After running a self-hosted agent, the error is the same.

Seeing online the details on the VSTS agents, I found that the highest .NetCore dependency they have installed is SDK 2.2.105. Going under agent's details, you can read

.NET Core
The following runtimes and SDKs are installed:

Environment:

PATH: contains location of dotnet.exe
SDK:

2.2.105 C:\Program Files\dotnet\sdk\2.2.105
2.2.104 C:\Program Files\dotnet\sdk\2.2.104
2.2.103 C:\Program Files\dotnet\sdk\2.2.103
2.2.102 C:\Program Files\dotnet\sdk\2.2.102

I was trying to troubleshoot on this way:

  1. Wait for Microsoft to update their online agents
  2. Create an on-prem agent(self-hosted agent), running on your localhost where you have all the dependencies installed
  3. try to add a step that installs the SDK as part of the agent's tasks(see the image below), but unfortunately, I couldn't make it work

Any thoughts?

enter image description here

2
You must have something wrong initially. ASP.NET Core 2.2 and later do not support web.config at all. Why do you insist to use web.config on ASP.NET Core 2.2+?Eriawan Kusumawardhono
I do not have webconfigsZinov
Ok. Looking at the build error, you might be having incorrect .NET TFM. Are you sure all of your projects have the correct TFM of .NET Core 2.2 SDK, in the solution? And you should add dotnet tool installer task first, before doing the build.Eriawan Kusumawardhono
That color contrast of the error message is illegible for me. It's also illegible to search engines, meaning that anyone else searching for terms in this error message will not find this question. Please reproduce all text relevant to your question in text form, not as images.spender
@spender, good point, thanks for your comments about the search engine, I just passed it, sorry, I just updated the question with the original textZinov

2 Answers

1
votes

If you don't want to use in-process hosting, delete the "AspNetCoreHostingModel" element from your .csproj:

   <PropertyGroup>
     <TargetFramework>netcoreapp2.1</TargetFramework>
     <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
   </PropertyGroup>
0
votes

As you see in Azure Pipelines VM images for Microsoft-hosted CI/CD, the highest .NET Core version which has been installed in hosted agent is SDK 2.2.105 with Runtime 2.2.3. But the version you installed to build project is .NET Core SDK 2.2.300 with Runtime 2.2.5. That's why you got that error message.

You can use task to install the matched version to support this build. Add extension .NET Core Global Tool Installer first, and use dotnet version 2.*(preview) task to install .NET Core SDK 2.2.300 with Runtime 2.2.5.