c - MSBuild 无法从 CLI 构建。无效的静态调用语法

标签 c visual-studio msbuild

我正在尝试使用 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 重建项目,那么项目构建没有任何问题。 enter image description here

尽管如此,我还是需要从 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/

相关文章:

c++ - 关于 C++ 中的指针和数组

c - C 编程作业简介

c++ - VC++ Glew 外部链接错误

msbuild - 指定的解决方案配置 "Latest|Any CPU"无效

c# - 在 MSBuild 任务中生成代码

c - 试图杀死一个生成的进程以一个已失效的进程结束

c - 简单的堆栈程序不接受输入并崩溃

c# - 尝试在 Java 服务器上连接时 UWP 客户端套接字 block ( Release模式)

C++ Visual Studio 字符编码问题

c# - 如果解决方案缺少引用的项目,则 MSBuild 解决方案构建失败