简体   繁体   English

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

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

I have ac# solution (open source, available here: https://github.com/tzachshabtay/MonoAGS ) which I can compile fine from Visual Studio 2017 (Dot net framework) and from VS for Mac (Mono). 我有一个ac#solution(开源,可以在这里: https//github.com/tzachshabtay/MonoAGS ),我可以从Visual Studio 2017(Dot net framework)和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 ). 我也可以在Linux和mac上成功地在Travis CI上用msbuild编译它( https://github.com/tzachshabtay/MonoAGS/blob/master/.travis.yml )。

What I can't do, is compile it on command-line from Windows 10 on my local machine. 我不能做的是在我的本地机器上从Windows 10在命令行上编译它。 I'd like to be able to compile it both for DotNet Framework and Mono. 我希望能够为DotNet Framework和Mono编译它。 So I tried using MSBuild from both the mono installation and from the Build Tools for Visual Studio 2017 (note: I want to be able to install on windows even if vs2017 is not installed, though on the local machine vs2017 is installed, don't know if it matters). 所以我尝试使用单声道安装和Build Tools for Visual Studio 2017Build Tools for Visual Studio 2017 MSBuild(注意:我希望能够在Windows上安装,即使没有安装vs2017,但是在本地机器上安装vs2017,不要知道这是否重要)。 Both installations are for the latest versions as of today. 这两个安装都是针对今天的最新版本。

This is the error I get from msbuild on mono ( PATH was set to %programfiles(x86)%\\Mono\\bin ): 这是我在单声道上从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). 项目“C:\\ Github \\ MonoAGS \\ MonoAGS.sln”(1)在节点1(默认目标)上构建“C:\\ Github \\ MonoAGS \\ Source \\ Tests \\ Tests.csproj”(2)。 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 \\ Tests \\ Tests.csproj”(2)在节点1上构建“C:\\ Github \\ MonoAGS \\ Source \\ AGS.API \\ AGS.API.csproj”(3)(GetTargetFrameworks目标(一个或多个))。 C:\\Program Files\\dotnet\\sdk\\2.1.4\\Sdks\\Microsoft.NET.Sdk\\Sdk\\Sdk.props(29,11): error MSB4226: The imported project "C:\\ Program Files (x86)\\MSBuild\\15.0\\Microsoft.Common.props" was not found. C:\\ Program Files \\ dotnet \\ sdk \\ 2.1.4 \\ Sdks \\ Microsoft.NET.Sdk \\ Sdk \\ Sdk.props(29,11):错误MSB4226:导入的项目“C:\\ Program Files(x86)\\ MSBuild \\ 15.0 \\ Microsoft.Common.props“未找到。 Also, tried to find "15.0\\Microsoft.Common.prop s" in the fallback search path(s) for $(MSBuildExtensionsPath) - "C:\\Program Files (x86)\\MSBuild" . 另外,尝试在$(MSBuildExtensionsPath) - “C:\\ Program Files(x86)\\ MSBuild”的后备搜索路径中找到“15.0 \\ Microsoft.Common.prop s”。 These search paths are defined in "C:\\Program Files\\Mono\\lib\\mono\\msbuild\\15.0\\bin\\MSBuild.dll.config". 这些搜索路径在“C:\\ Program Files \\ Mono \\ lib \\ mono \\ msbuild \\ 15.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. [C:\\ Github上\\ MonoAGS \\源\\ AGS。 API\\AGS.API.csproj] API \\ AGS.API.csproj]

And here's the error I get from msbuild from build tools ( PATH was set to %programfiles(x86)%\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.0\\Bin ): 这是我从构建工具从msbuild获得的错误( PATH设置为%programfiles(x86)%\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.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 \\ Tests \\ Tests.csproj”(2)在节点1上构建“C:\\ Github \\ MonoAGS \\ Source \\ AGS.API \\ AGS.API.csproj”(3)(GetTargetFrameworks目标(一个或多个))。 C:\\Github\\MonoAGS\\Source\\AGS.API\\AGS.API.csproj : error MSB4247: Could not load SDK Resolver. C:\\ Github \\ MonoAGS \\ Source \\ AGS.API \\ AGS.API.csproj:错误MSB4247:无法加载SDK解析器。 A manifest file exists, but the path to the SDK Resolver DLL file could not be found. 存在清单文件,但找不到SDK解析程序DLL文件的路径。 Manifest file path 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.0\\Bin\\SdkResolvers\\Microsoft.Build.NuGet SdkResolver\\Microsoft.Build.NuGetSdkResolver.xml'. 清单文件路径'C:\\ Program Files(x86)\\ Microsoft Visual Studio \\ 2017 \\ BuildTools \\ MSBuild \\ 15.0 \\ Bin \\ SdkResolvers \\ Microsoft.Build.NuGet SdkResolver \\ Microsoft.Build.NuGetSdkResolver.xml'。 SDK resolver path: C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\Common7\\IDE\\CommonExtens ions\\Microsoft\\NuGet\\Microsoft.Build.NuGetSdkResolver.dll SDK解析器路径:C:\\ Program Files(x86)\\ Microsoft Visual Studio \\ 2017 \\ BuildTools \\ Common7 \\ IDE \\ CommonExtens ions \\ Microsoft \\ NuGet \\ Microsoft.Build.NuGetSdkResolver.dll

As for the mono error, the MSBuild\\15.0 folder exists but Microsoft.Common.props is not there (and I couldn't find it anywhere else on that machine). 至于单声道错误, MSBuild\\15.0文件夹存在,但Microsoft.Common.props不存在(我无法在该机器上的任何其他地方找到它)。

As for the build tools error, the CommonExtensions folder exists but there is no Microsoft folder in it. 至于构建工具错误, CommonExtensions文件夹存在,但其中没有Microsoft文件夹。

The command I'm trying is: msbuild /p:Configuration=DEBUG /p:Platform="Any CPU" MonoAGS.sln 我正在尝试的命令是: msbuild /p:Configuration=DEBUG /p:Platform="Any CPU" MonoAGS.sln

Why doesn't it work? 为什么不起作用? What am I missing? 我错过了什么? Thanks. 谢谢。

How to compile my c# solution with msbuild from command line 如何使用msbuild从命令行编译我的c#解决方案

For the build tools error, you should install the component NuGet package manager by Visual Studio Installer: 对于构建工具错误,您应该通过Visual Studio Installer安装组件NuGet包管理器

在此输入图像描述

When we use the Visual Studio build tool to build our project, we also need to install some of the necessary components for our project. 当我们使用Visual Studio构建工具来构建项目时,我们还需要为项目安装一些必要的组件。

For the mono error, since I do not have mono ENV, I could not specify the directly reason for that error, if possible, you can try to install Mono framework . 对于单声道错误,由于我没有单声道ENV,我无法指定该错误的直接原因,如果可能,您可以尝试安装Mono框架 If it not helps, you can open a new thread with mono and msbuild tags. 如果没有帮助,您可以使用mono和msbuild标签打开一个新线程。

Update: 更新:

How do I install it with command-line, btw (for setting up a script)? 如何使用命令行,btw(用于设置脚本)安装它?

Yes, you can use vs_buildtools.exe to install that component ID Microsoft.VisualStudio.Component.NuGet : 是的,您可以使用vs_buildtools.exe来安装该组件ID Microsoft.VisualStudio.Component.NuGet

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

Note: You should rename vs_buildtools__2048890300.15156xxxx.exe to vs_buildtools.exe, then use vs_buildtools.exe to install it. 注意:您应该将vs_buildtools__2048890300.15156xxxx.exe重命名为vs_buildtools.exe,然后使用vs_buildtools.exe进行安装。

Check the Visual Studio Build Tools 2017 component directory and Use command-line parameters to install Visual Studio 2017 for some more details. 检查Visual Studio Build Tools 2017组件目录使用命令行参数安装Visual Studio 2017以获取更多详细信息。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用命令行中的C#7代码构建.csproj(msbuild) - How to build .csproj with C# 7 code from command line (msbuild) 如何从命令行或 C# 应用程序检测 msbuild 的状态 - How to detect the status of msbuild from command line or C# Application 为什么我的解决方案在Visual Studio中构建,而不是使用msbuild从命令行构建? - How come my solution builds in Visual Studio but not from the command line using msbuild? 使用mdtool命令行在Windows上编译ac#解决方案 - use mdtool command line to compile a c# solution on Windows Visual Studio生成解决方案,但命令行中的MSBuild失败 - Visual Studio builds solution but MSBuild from the command line fails 如何在命令行中编译ZipFile类(C#) - How to compile ZipFile class (C#) in command line 如何在命令行中从msbuild配置csc? - How configure csc from msbuild in command line? 在某些计算机上从命令行执行C#msbuild执行会跳过签名阶段WP8 - c# msbuild execution from command line on some computersskips the signing phase WP8 使用C#代码中的msbuild构建Visual Studio解决方案 - Build visual studio solution using msbuild from c# code 具有C#6.0代码的MSBuild命令行无法构建 - MSBuild command line with C# 6.0 code fails to build
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM