MSBuild cannot build from CLI. Invalid static invocation syntax

Viewed 1780

I am trying to compile a C VS project from PowerShell using msbuild. The command I'm using for now is:

msbuild .\my_solution.sln /t:Rebuild /p:Configuration=Release

But when I try to build I get the following error:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.Cpp.props(31,5): error MSB4186: Invalid static method invocation syntax: "[Microsoft.Build.Utilities.ToolLocat
ionHelper]::FindRootFolderWhereAllFilesExist($(_VCTargetsPathFolders), $(_RelativeToolsetFiles))". Method 'Microsoft.Build.Utilities.ToolLocationHelper.FindRootFolderWhereAllFilesExist' not found. Static meth
od invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)).

I have already tried the following:

  • Run as admin
  • Repair Visual Studio
  • Full uninstall and reinstall of Visual Studio.

Other useful info:

  • I am using Visual Studio Community 2019.
  • My msbuild path is: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin
  • My VCTargetsPath is: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\
  • Worth noting that on the CLI command I haven't added the additional include directories nor the additional dependencies while in the UI version I have. Despite this, the error I am expecting is somewhat like unknown reference to <function>. I am trying to solve this first error before proceeding to link the required libraries, I don't believe this causes the problem but I'm mentioning it just in case.

The strange thing is that if I rebuild using the Visual Studio UI the project builds without any problem. enter image description here

Despite this, I need to build from CLI so I would be really thankful if someone shares where the problem may be.

2 Answers

Check your MSBuild version, I've had the same problem time ago.

For example:

msbuild
Microsoft (R) Build Engine version 4.0.30319 for .NET Framework

In my case (now), the latest version is 16.9.0 (Downloaded from here)

Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET Framework

Check your Windows Path, when I got the problem, I got a Windows Path that contains an older version of MSBuild, checking the folder I saw "msbuild.exe". I Removed that entry and put the new one for my good msbuild.

%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin

Seen on this post

This works well in my side with your description. So your environment has some problems.

Try these:

1) close VS IDE, run Developer Command Prompt for VS2019 as Administrator

type:

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Build.Framework.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Build.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Build.Engine.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Build.Conversion.Core.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Build.Tasks.Core.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Build.Utilities.Core.dll"

After that, restart it to test again.

This is up to your wish:

If it does not help, please run C:\Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\layout\InstallCleanup.exe to uninstall all VS2017 andVS2019 versions with their registration information, any data. This is like a strong, thorough uninstallation.

Then, reinstall the version.

Related