简体   繁体   中英

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). 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 ).

What I can't do, is compile it on command-line from Windows 10 on my local machine. I'd like to be able to compile it both for DotNet Framework and 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). 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 ):

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\\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. 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\\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. 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 ):

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 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

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).

As for the build tools error, the CommonExtensions folder exists but there is no Microsoft folder in it.

The command I'm trying is: 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

For the build tools error, you should install the component NuGet package manager by Visual Studio Installer:

在此输入图像描述

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.

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 . If it not helps, you can open a new thread with mono and msbuild tags.

Update:

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

Yes, you can use vs_buildtools.exe to install that component 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.

Check the Visual Studio Build Tools 2017 component directory and Use command-line parameters to install Visual Studio 2017 for some more details.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM