简体   繁体   中英

Why is msbuild.exe missing in C:\Program Files\dotnet\sdk\3.1.201? Causing AzureDevOps build step to fail

I have a very simple WPF project (.Net 4.7.2) and Unit Test project (MSTest.Net Core) and I'm trying to get it to build in Azure Pipelines and I'm getting following error:

2020-05-07T16:41:52.9562570Z C:\Program Files\dotnet\sdk\3.1.201\Microsoft.Common.CurrentVersion.targets(3032,5): error MSB4216: Could not run the "GenerateResource" task because MSBuild could not create or connect to a task host with runtime "CLR4" and architecture "x86". Please ensure that (1) the requested runtime and/or architecture are available on the machine, and (2) that the required executable "C:\Program Files\dotnet\sdk\3.1.201\MSBuild.exe" exists and can be run. [C:\agent_work\4\s\RsSolution4\WpfApp1\WpfApp1.csproj] 2020-05-07T16:41:53.1174401Z ##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1

I looked for msbuild.exe in suggested folder and sure enough it doesn't exist. The path exists and there are many files in folder, just not msbuild.exe. There's an msbuild.dll.

Here's my yaml file:

trigger:
- master

pool: 
  name: Default
  demands: msbuild

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: DotNetCoreCLI@2
  displayName: Restore NuGet
  inputs:
    command: 'custom'
    projects: '**/*.csproj'
    custom: 'restore'

- task: MSBuild@1
  inputs:
    solution: '**/*.sln'
    msbuildLocationMethod: 'location'
    msbuildLocation: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\msbuild.exe'
    configuration: 'Release'    
    clean: true

- task: DotNetCoreCLI@2
  displayName: SSP Automated Testing
  inputs:
    command: 'test'
    projects: '**/*Test*.csproj'
    arguments: '--configuration $(buildConfiguration)'
    testRunTitle: 'SSP Testing'

make sure you add a UseDotNet task to ensure the correct version of the SDK is available on the agent:

- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '3.1.201'

And I'd opt to use the dotnet build task to build the .NET Core project and the VisualStudioBuild task for the WPF project, that way you're not intermingling framework types and SDKs in then same solution build.

It seems like this known issue for dotnet core. It said On .NET Core, MSBuild doesn't support task hosts of different architectures/runtime versions .

The workaround provided is to add CurrentArchitecture/CurrentRuntime to PropertyGroup . See this similar issue .

 <PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Core' Or '$(TargetFrameworkIdentifier)' != '.NETFramework'">
    <GenerateResourceMSBuildArchitecture Condition=" '$(GenerateResourceMSBuildArchitecture)' == '' ">CurrentArchitecture</GenerateResourceMSBuildArchitecture>
    <GenerateResourceMSBuildRuntime Condition=" '$(GenerateResourceMSBuildRuntime)' == '' ">CurrentRuntime</GenerateResourceMSBuildRuntime>
  </PropertyGroup> 

You also try using msbuild task only to build all your projects, for msbuild works for both .net framework and .net core. You can specify solutions and projects for the solution parameter of Msbuild task .

Since there are.Net framework projects and.Net Core projects in your solution. I would suggest using Nuget restore task to restore the solution. Dotnet cli doesnot works properly with .NET Framework, which wil probably fail to restore the .net framework projects.

Hope above helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM