为什么C:\ Program Files \ dotnet \ sdk \ 3.1.201中缺少msbuild.exe?导致AzureDevOps构建步骤失败 [英] Why is msbuild.exe missing in C:\Program Files\dotnet\sdk\3.1.201? Causing AzureDevOps build step to fail

查看:1058
本文介绍了为什么C:\ Program Files \ dotnet \ sdk \ 3.1.201中缺少msbuild.exe?导致AzureDevOps构建步骤失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的WPF项目(.Net 4.7.2)和单元测试项目(MSTest .Net Core),并且我试图将其构建在Azure Pipelines中,并且出现以下错误:

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 文件\ dotnet \ sdk \ 3.1.201 \ Microsoft.Common.CurrentVersion.targets(3032,5): 错误MSB4216:无法运行"GenerateResource"任务,因为 MSBuild无法使用运行时"CLR4"创建或连接到任务主机 和架构"x86".请确保(1)请求的运行时 和/或体系结构在计算机上可用,并且(2) 所需的可执行文件"C:\ Program Files \ dotnet \ sdk \ 3.1.201 \ MSBuild.exe" 存在并且可以运行. [C:\ agent_work \ 4 \ s \ RsSolution4 \ WpfApp1 \ WpfApp1.csproj] 2020-05-07T16:41:53.1174401Z ## [错误]错误:进程'C:\ Program Files \ dotnet \ dotnet.exe'失败,退出代码为1

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

我在建议的文件夹中寻找了msbuild.exe,并确定它不存在.该路径存在并且文件夹中有很多文件,只是msbuild.exe没有.有一个msbuild.dll.

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.

这是我的Yaml文件:

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'

推荐答案

似乎此已知问题.它说On .NET Core, MSBuild doesn't support task hosts of different architectures/runtime versions.

提供的解决方法是将CurrentArchitecture/CurrentRuntime添加到 PropertyGroup .看到此类似问题.

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> 

您还可以尝试仅使用msbuild任务来构建所有项目,因为msbuild适用于.net框架和.net核心.您可以为

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.

由于您的解决方案中包含.Net框架项目和.Net Core项目.我建议使用 Nuget还原任务来还原解决方案. Dotnet cli无法与.NET Framework一起正常使用,这可能无法还原.net Framework项目.

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.

希望上面有帮助!

这篇关于为什么C:\ Program Files \ dotnet \ sdk \ 3.1.201中缺少msbuild.exe?导致AzureDevOps构建步骤失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆