Home > Net >  MSBuild failure: IsOsPlatform not found
MSBuild failure: IsOsPlatform not found

Time:06-22

One of our developers has created a project which builds successfully using Visual Studio 2017 on his PC. I want to build the project on an Azure virtual machine, from an Azure Pipeline. Since it will be from a pipeline, I cannot use the Visual Studio UI. So I'm trying to build it from the command line first, and if that works, I will add a pipeline task to do it.

This project uses NuGet to install some MongoDB packages. This complication confused the troubleshooting at first, because it appeared to be a MongoDB issue, but it is not.

First problem:

"C:\workspace\xxxxx\xxxxx.sln" (default target) (1) ->
"C:\workspace\xxxxx\xxxxx.csproj" (default target) (2) ->
C:\workspace\xxxxx\packages\MongoDB.Libmongocrypt.1.0.0\build\MongoDB.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`)).`

I could not find much information online about this error message, but after reading what I did find (for example, this MongoDB Jira entry, it sounded like I might need to update MSBuild.

  • MSBuild on the PCs where the build was successful: version 15.9.21.
  • MSBuild on the VM where the build was not successful: version 15.1.155

From this StackOverflow thread, I concluded that it was dangerous to try updating MSBuild by itself, or to take a piecemeal approach. I chose to update the entire VS 2017 application.

The Azure VM is a self-hosted Standard DS3 v2 machine, with the plan VS-2017-Ent-WS2016. It came with VS 2017 installed. I went to Windows "Features and Applications", selected VS 2017, and updated the entire application from there.

Now MSBuild on the Azure VM is version 15.9.21. The error goes away. First problem solved.

Second problem:

The build still fails, but with a different error.

"C:\workspace\xxxxx\xxxxx.sln" (default target) (1) ->
"C:\workspace\xxxxx\xxxxx.csproj" (default target) (2) ->
(GetReferenceAssemblyPaths target) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\
bin\Microsoft.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:\workspace\xxxxxx\xxxxx.csproj]

How do I fix this second build error?

Additional data

The command ls C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework lists the newest frameworks as v4.6.1, v4.6.2, v4.7.1, and v4.X, all timestamped today, as a result of my VS2017 update.

I downloaded the Microsoft .NET Framework v4.7.2 Setup, ndp472-kb4054531-web.exe, from the official website. When I attempted to run it, I got a blocked installation, with the reason ".NET Framework 4.7.2 or a later update is already installed on this computer."

CodePudding user response:

To fix the error:

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

download/install the 4.7.2 SDK which contains the targeting pack. Also see To install the .NET Framework Developer Pack or Targeting Pack


Here are some other resources that may be useful:

  • Related