我正在尝试使用 msbuild
从 PowerShell 编译一个 C VS 项目.我现在使用的命令是:
msbuild .\my_solution.sln /t:Rebuild /p:Configuration=Release
但是当我尝试构建时出现以下错误:
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`)).
我已经尝试过以下方法:
- 以管理员身份运行
- 修复 Visual Studio
- 完全卸载并重新安装 Visual Studio。
其他有用信息:
- 我正在使用 Visual Studio Community 2019。
- 我的
msbuild
路径是:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin
- 我的
VCTargetsPath
是:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\
- 值得注意的是,在我拥有的 UI 版本中,我没有在 CLI 命令中添加额外的包含目录或额外的依赖项。尽管如此,我期待的错误有点像
unknown reference to <function>
.在继续链接所需的库之前,我试图解决第一个错误,我认为这不会导致问题,但我提到它以防万一。
奇怪的是,如果我使用 Visual Studio UI 重建项目,那么项目构建没有任何问题。
尽管如此,我还是需要从 CLI 构建,所以如果有人分享问题所在,我将非常感激。
最佳答案
检查你的 MSBuild 版本,我以前遇到过同样的问题。
例如:
msbuild
Microsoft (R) Build Engine version 4.0.30319 for .NET Framework
就我而言(现在),最新版本是 16.9.0(从 here 下载)
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET Framework
检查您的 Windows 路径,当我遇到问题时,我得到一个包含旧版本 MSBuild 的 Windows 路径,检查我看到“msbuild.exe”的文件夹。我删除了该条目并为我的好 msbuild 添加了新条目。
%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin
见于 this post
关于c - MSBuild 无法从 CLI 构建。无效的静态调用语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66731637/