c - MSBuild 无法从 CLI 构建。无效的静态调用语法
问题描述
我正在尝试使用msbuild
. 我现在使用的命令是:
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 社区 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(从这里下载)
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
看到这个帖子
推荐阅读
- ios - CALayer 自动布局
- r - R 警告:条件的长度 > 1,并且只会使用第一个元素。外功能
- c# - 不可调用的 Hashtable.keys 成员不能用作方法
- java - 是否可以在 camunda 中使用 Fluent API 更新正在运行的流程实例?
- python - 这个 Power Set 程序的复杂性是什么?
- mysql - 按未处理 MySql 中的临时表排序
- pandas - Pandas 中列的成对差异
- ionic3 - 如何使用 Ionic 3 运行 Android 的活动或服务
- c# - 如果 .Net Core 可以在 Windows 上运行,为什么不能在 .Net Framework 中引用 .Net Core DLL?
- c - C Unicode:如何将 C11 标准修订 DR488 修复应用于 C11 标准函数 c16rtomb()?