When I type...
Msbuild<Enter>
...at the command prompt, I get...
Microsoft (R) Build Engine Version 2.0.50727.4927
[Microsoft .NET Framework, Version 2.0.50727.4927]
Copyright (C) Microsoft Corporation 2005. All rights reserved.
This is all very well and good except that when I run this against a Visual Studio 2010 .sln
file, the error message indicates:
MyProject.sln(2): Solution file error MSB5014: File format version is not recognized. MSBuild can only read solution files between versions 7.0 and 9.0, inclusive.
0 Warning(s)
1 Error(s)
It would appear that the version of MSBuild that is being called, is not capable of understanding my solution file.
I figured that I would chec开发者_Go百科k out my path and see where MSBuild is being picked up from. However, it seems that no part of my path points at a location where MSBuild is to be found.
How is the command line finding the copy of MSBuild that it is using and how can I change this version so that the latest version is used?
I found this question as my PATH
variable did not contain a reference to MSBuild.exe
. In case anyone else is having this issue, my resolution was to explictly register the environment variables for Visual Studio tools from the command prompt:
"%VS100COMNTOOLS%"\\vsvars32.bat // VS2010 environment variables
"%VS110COMNTOOLS%"\\vsvars32.bat // VS2012 environment variables
"%VS120COMNTOOLS%"\\vsvars32.bat // VS2013 environment variables
MSBuild.exe
is now registered in PATH
where msbuild
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe
It must be somewhere in the PATH environment. Use 'where msbuild' to determine where it is loading msbuild from.
Use the Visual Studio Command Prompt (2010) shortcut to initialize the path and other environment variables for VS 2010 and MSBuild 4.0.
Change your environment variables.
Find/set your MSBuild path variable to be C:\Windows\Microsoft.NET\Framework\v4.0.30319
Obiviously the above path will depend on your installation location, but it will be close if not exact.
For building a C# 6 project, this worked for me in a batch file
if exist "%ProgramFiles(x86)%\MSBuild\14.0\bin" set MSBUILDLOCATION=%ProgramFiles(x86)%\MSBuild\14.0\bin
if exist "%ProgramFiles%\MSBuild\14.0\bin" set MSBUILDLOCATION=%ProgramFiles%\MSBuild\14.0\bin
"%MSBUILDLOCATION%\msbuild.exe" "path\to\my\project.csproj"
You can easily change the version number (14.0) or add lines with more version numbers (12.0 and 4.0 for example) if you wanted to support a range of versions.
精彩评论