如何从命令行使用 msbuild 编译我的 C# 解决方案

How to compile my c# solution with msbuild from command line

我有一个 C# 解决方案(开源,可在此处获取:https://github.com/tzachshabtay/MonoAGS) which I can compile fine from Visual Studio 2017 (Dot net framework) and from VS for Mac (Mono). I can also compile it with msbuild on Travis CI successfully on both linux and mac (https://github.com/tzachshabtay/MonoAGS/blob/master/.travis.yml)。

我不能做的是在本地计算机上从 Windows 10 在命令行上编译它。我希望能够为 DotNet Framework 和 Mono 编译它。 因此,我尝试从单声道安装和 Build Tools for Visual Studio 2017 中使用 MSBuild(注意:即使未安装 vs2017,我也希望能够在 windows 上安装,尽管在本地计算机上安装了 vs2017,不知道有没有关系)。 这两个安装都是针对今天的最新版本。

这是我在单声道上从 msbuild 得到的错误(PATH 设置为 %programfiles(x86)%\Mono\bin):

Project "C:\Github\MonoAGS\MonoAGS.sln" (1) is building "C:\Github\MonoAGS\Source\Tests\Tests.csproj" (2) on node 1 (default targets). Project "C:\Github\MonoAGS\Source\Tests\Tests.csproj" (2) is building "C:\Github\MonoAGS\Source\AGS.API\AGS.API.csproj" (3) on node 1 (GetTargetFrameworks target(s)). C:\Program Files\dotnet\sdk.1.4\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props(29,11): error MSB4226: The imported project "C:\ Program Files (x86)\MSBuild.0\Microsoft.Common.props" was not found. Also, tried to find "15.0\Microsoft.Common.prop s" in the fallback search path(s) for $(MSBuildExtensionsPath) - "C:\Program Files (x86)\MSBuild" . These search paths are defined in "C:\Program Files\Mono\lib\mono\msbuild.0\bin\MSBuild.dll.config". Confirm that the path in the declaration is correct, and that the file exists on disk in one of the search paths. [C:\Github\MonoAGS\Source\AGS. API\AGS.API.csproj]

这是我从构建工具的 msbuild 得到的错误(PATH 设置为 %programfiles(x86)%\Microsoft Visual Studio17\BuildTools\MSBuild.0\Bin):

Project "C:\Github\MonoAGS\Source\Tests\Tests.csproj" (2) is building "C:\Github\MonoAGS\Source\AGS.API\AGS.API.csproj" (3) on node 1 (GetTargetFrameworks target(s)). C:\Github\MonoAGS\Source\AGS.API\AGS.API.csproj : error MSB4247: Could not load SDK Resolver. A manifest file exists, but the path to the SDK Resolver DLL file could not be found. Manifest file path 'C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\MSBuild.0\Bin\SdkResolvers\Microsoft.Build.NuGet SdkResolver\Microsoft.Build.NuGetSdkResolver.xml'. SDK resolver path: C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\Common7\IDE\CommonExtens ions\Microsoft\NuGet\Microsoft.Build.NuGetSdkResolver.dll

至于单声道错误,MSBuild.0 文件夹存在但 Microsoft.Common.props 不存在(而且我在那台机器上的其他任何地方都找不到它)。

至于构建工具错误,CommonExtensions文件夹存在,但其中没有Microsoft文件夹。

我正在尝试的命令是: msbuild /p:Configuration=DEBUG /p:Platform="Any CPU" MonoAGS.sln

为什么不起作用?我错过了什么? 谢谢。

How to compile my c# solution with msbuild from command line

对于构建工具错误,您应该通过 Visual Studio 安装程序安装组件 NuGet 包管理器

当我们使用Visual Studio构建工具构建我们的项目时,我们还需要为我们的项目安装一些必要的组件。

对于mono错误,由于我没有mono ENV,所以无法直接说明错误的原因,如果可能,您可以尝试安装Mono framework。如果没有帮助,您可以使用 mono 和 msbuild 标签打开一个新线程。

更新:

How do I install it with command-line, btw (for setting up a script)?

是的,您可以使用 vs_buildtools.exe 安装该组件 ID Microsoft.VisualStudio.Component.NuGet:

vs_buildtools.exe --add Microsoft.VisualStudio.Component.NuGet --quiet

注意:您应该将 vs_buildtools__2048890300.15156xxxx.exe 重命名为 vs_buildtools.exe,然后使用 vs_buildtools.exe 进行安装。

查看 Visual Studio Build Tools 2017 component directory and Use command-line parameters to install Visual Studio 2017 了解更多详情。

希望这对您有所帮助。