首页 > 解决方案 > 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 UI 进行重建,项目的构建没有任何问题。 在此处输入图像描述

尽管如此,我需要从 CLI 构建,所以如果有人分享问题所在,我将非常感激。

标签: cvisual-studiomsbuild

解决方案


检查您的 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

看到这个帖子


推荐阅读