1

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.

PauMAVA
  • 751
  • 7
  • 14

2 Answers2

2

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

Masplus
  • 71
  • 4
  • 2
    Thank you very much! I had an old entry in my Path pointing to `C:\Windows\Microsoft.NET\Framework64\v4.0.30319` before the entry to `%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin` so the executed version of `msbuild.exe` was `4.0.40319` but using the property files found in the `16.9.2` path thus failing in unpredictable ways. By removing `C:\Windows\Microsoft.NET\Framework64\v4.0.30319` from the path it worked like a charm. – PauMAVA Mar 23 '21 at 21:19
1

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.

Perry Qian-MSFT
  • 13,922
  • 1
  • 6
  • 20
  • Hello. First of all thanks for your response. Unfortunately, I have tried the two methods you have suggested but none of them have worked for me. Still getting the same error. Thanks for taking the time to write a response. If you know of any other thing that may solve the error please feel free to share it. – PauMAVA Mar 22 '21 at 13:05
  • That is too strange. Did you try this issue on another PC? Or just install [Build Tool for VS2019](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019), did it work? Also, I am not sure whether the problem is related to your project itself. If possible, please share your project demo with us. – Perry Qian-MSFT Mar 23 '21 at 09:29