MSBuild failure: IsOsPlatform not found



我们的一个开发人员创建了一个项目,该项目在他的PC上使用Visual Studio 2017成功构建。我想从Azure Pipeline在Azure虚拟机上构建项目。因为它将来自管道,所以我不能使用Visual Studio UI。所以我试着先从命令行构建它,如果这样可以,我将添加一个管道任务来完成它。

本项目使用NuGet安装部分MongoDB包。这种复杂性一开始混淆了故障排除,因为它似乎是MongoDB的问题,但它不是。

第一个问题:

"C:workspacexxxxxxxxxx.sln" (default target) (1) ->
"C:workspacexxxxxxxxxx.csproj" (default target) (2) ->
C:workspacexxxxxpackagesMongoDB.Libmongocrypt.1.0.0buildMongoDB.Libmongocrypt.targets(4,16):
error MSB4186: Invalid static method invocation syntax: "MSBuild]::IsOsPlatform('Windows')".
Method '[MSBuild]::IsOsPlatform' not found. Static method invocation should be of the form:
$([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)).`

我在网上找不到关于这个错误消息的很多信息,但是在阅读了我所发现的(例如,这个MongoDB Jira条目)之后,听起来我可能需要更新MSBuild。

  • MSBuild: 15.9.21版本。
  • 在构建不成功的VM上的MSBuild: version 15.1.155

从这个StackOverflow线程,我得出结论,这是危险的尝试更新MSBuild本身,或采取零碎的方法。我选择更新整个VS 2017应用程序。

Azure VM是一台自托管的标准DS3 v2机器,计划为VS-2017-Ent-WS2016。它是与VS 2017一起安装的。我去了Windows"功能和应用程序",选择了VS 2017,并从那里更新了整个应用程序。

现在Azure虚拟机上的MSBuild版本是15.9.21。错误消失了。第一个问题解决了

第二个问题:

构建仍然失败,但是有一个不同的错误。

"C:workspacexxxxxxxxxx.sln" (default target) (1) ->
"C:workspacexxxxxxxxxx.csproj" (default target) (2) ->
(GetReferenceAssemblyPaths target) ->
C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0
binMicrosoft.Common.CurrentVersion.targets(1179,5):
error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.7.2" were not found.
To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application 
to a version of the framework for which you have the SDK or Targeting Pack installed. 
Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. 
Therefore your assembly may not be correctly targeted for the framework you intend.
[C:workspacexxxxxxxxxxx.csproj]

如何修复这第二个构建错误?

额外数据

命令ls C:Program Files (x86)Reference AssembliesMicrosoftFramework列出了最新的框架v4.6.1、v4.6.2、v4.7.1和v4。X,今天所有的时间戳,由于我的VS2017更新。

我下载了Microsoft .NET Framework v4.7.2 Setup,ndp472-kb4054531-web.exe,从官网下载。当我试图运行它时,安装被阻止了,原因是"。. NET Framework 4.7.2或更高版本的更新已安装在此计算机上。">

修复错误:

.NETFramework的参考程序集,Version=v4.7.2没有找到。要解决此问题,请安装SDK或目标包这个框架版本

下载/安装包含目标包的4.7.2 SDK。参见安装。net Framework Developer Pack或Targeting Pack


下面是一些可能有用的资源:

  • 使用.vsconfig
  • 在整个组织中配置Visual Studio
  • 如何从命令行使用指定的配置文件vs2019 for c++ ?
  • Azure上的Visual Studio映像(安装了哪些功能)
  • Visual Studio安装命令行参数示例