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:
Other useful info:
msbuild path is: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\BinVCTargetsPath is: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\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.

Despite this, I need to build from CLI so I would be really thankful if someone shares where the problem may be.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With