如何使用Windows SDK 7.1从命令行运行msbuild?
我正在CI服务器上设置.NET 4.0支持。 我已经安装了.NET 4.0以及Windows 7.1 SDK中的.NET工具。
在.NET 2.0和3.5,这只是工作。 在.NET 4中,当我从开始菜单运行“Windows SDK 7.1命令提示符”时,它会抱怨
The x86 compilers are not currently installed. x86-x86 Please go to Add/Remove Programs to update your installation. . Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v7.1 \. Targeting Windows Server 2008 x86 Debug
然后当我尝试运行msbuild时,我得到:
C:\Program Files\Microsoft SDKs\Windows\v7.1>msbuild 'msbuild' is not recognized as an internal or external command, operable program or batch file. C:\Program Files\Microsoft SDKs\Windows\v7.1>
我不能相信,安装运行时和SDK会留下一个系统,无法运行msbuild …我错过了一些明显的步骤或隐晦的Windows更新,或者是放弃,并开始黑客的系统path?
要在命令提示符中启用msbuild
,只需将计算机上安装的.NET 4 Framework的path添加到PATH
环境variables即可。
您可以通过以下方式访问环境variables:
- 右键单击计算机
- 点击属性
- 然后点击左侧导航栏上的高级系统设置
- 在下一个对话框中单击环境variables
- 向下滚动到
PATH
- 编辑它以包含您的框架path(不要忘记在这里的最后一个条目后的“ ; ”)。
作为参考,我的path是C:\Windows\Microsoft.NET\Framework\v4.0.30319
。
从Visual Studio 2013
开始, MSbuild
就成为Visual Studio的一部分。 早些时候,MSBuild被安装作为一部分。 NET框架。
MSBuild直接安装在%ProgramFiles%下 。 所以,根据Visual Studio的版本,MSBuild的path可能会有所不同。
对于Visual Studio 2015
, MSBuild
path是"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
对于Visual Studio 15 Preview
, MSBuild
path是"%ProgramFiles(x86)%\MSBuild\15.0\Bin\MSBuild.exe"
此外,一些新的MSBuild属性已被添加,一些已被修改。 欲了解更多信息看这里
更新1:VS 2017
随着Visual Studio 2017的发布,MSBuild的位置又发生了变化。 现在,安装目录位于%ProgramFiles(x86)%\Microsoft Visual Studio\2017\[VS Edition]\15.0\Bin\
。 因为我有一个企业版本,我的机器的MSBuild位置是"%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSbuild.exe"
你的bat文件可能是这样的:
CD C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319
msbuild C:\ Users \ mmaratt \ Desktop \ BladeTortoise \ build \ ALL_BUILD.vcxproj
暂停
出口
为了能够使用C#6语法来构build,请使用以下path:
C:\ Program Files(x86)\ MSBuild \ 14.0 \ Bin
在设置要添加到PATH
条目之前,“SDK命令提示符”快捷方式运行的SetEnv.cmd
脚本在各个位置运行检查cl.exe
。 因此,如果没有安装本地C编译器,则无法添加任何内容。
要解决此问题,请将以下修补程序应用于<SDK install dir>\Bin\SetEnv.cmd
。 这也将修复位于<SDK install dir>\Bin
和子文件夹中的其他工具的缺失path。 当然,你可以安装C编译器来解决这个bug。
--- SetEnv.Cmd_ 2010-04-27 19:52:00.000000000 +0400 +++ SetEnv.Cmd 2013-12-02 15:05:30.834400000 +0400 @@ -228,10 +228,10 @@ IF "%CURRENT_CPU%" =="x64" ( IF "%TARGET_CPU%" == "x64" ( + SET "FxTools=%FrameworkDir64%\%FrameworkVersion%;%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework64\v3.5;%windir%\Microsoft.NET\Framework\v3.5;" + SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools\x64;%WindowsSdkDir%Bin\x64;%WindowsSdkDir%Bin;" IF EXIST "%VCTools%\amd64\cl.exe" ( SET "VCTools=%VCTools%\amd64;%VCTools%\VCPackages;" - SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools\x64;%WindowsSdkDir%Bin\x64;%WindowsSdkDir%Bin;" - SET "FxTools=%FrameworkDir64%\%FrameworkVersion%;%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework64\v3.5;%windir%\Microsoft.NET\Framework\v3.5;" ) ELSE ( SET VCTools= ECHO The x64 compilers are not currently installed. @@ -239,10 +239,10 @@ ECHO . ) ) ELSE IF "%TARGET_CPU%" == "IA64" ( + SET "FxTools=%FrameworkDir64%\%FrameworkVersion%;%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework64\v3.5;%windir%\Microsoft.NET\Framework\v3.5;" + SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools\x64;%WindowsSdkDir%Bin\x64;%WindowsSdkDir%Bin;" IF EXIST "%VCTools%\x86_ia64\cl.exe" ( SET "VCTools=%VCTools%\x86_ia64;%VCTools%\VCPackages;" - SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools\x64;%WindowsSdkDir%Bin\x64;%WindowsSdkDir%Bin;" - SET "FxTools=%FrameworkDir64%\%FrameworkVersion%;%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework64\v3.5;%windir%\Microsoft.NET\Framework\v3.5;" ) ELSE ( SET VCTools= ECHO The IA64 compilers are not currently installed. @@ -250,10 +250,10 @@ ECHO . ) ) ELSE IF "%TARGET_CPU%" == "x86" ( + SET "FxTools=%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework\v3.5;" + SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools;%WindowsSdkDir%Bin;" IF EXIST "%VCTools%\cl.exe" ( SET "VCTools=%VCTools%;%VCTools%\VCPackages;" - SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools;%WindowsSdkDir%Bin;" - SET "FxTools=%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework\v3.5;" ) ELSE ( SET VCTools= ECHO The x86 compilers are not currently installed. @@ -263,10 +263,10 @@ ) ) ELSE IF "%CURRENT_CPU%" =="IA64" ( IF "%TARGET_CPU%" == "IA64" ( + SET "FxTools=%FrameworkDir64%\%FrameworkVersion%;%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework64\v3.5;%windir%\Microsoft.NET\Framework\v3.5;" + SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools\IA64;%WindowsSdkDir%Bin\IA64;%WindowsSdkDir%Bin;" IF EXIST "%VCTools%\IA64\cl.exe" ( SET "VCTools=%VCTools%\IA64;%VCTools%;%VCTools%\VCPackages;" - SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools\IA64;%WindowsSdkDir%Bin\IA64;%WindowsSdkDir%Bin;" - SET "FxTools=%FrameworkDir64%\%FrameworkVersion%;%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework64\v3.5;%windir%\Microsoft.NET\Framework\v3.5;" ) ELSE ( SET VCTools= ECHO The IA64 compilers are not currently installed. @@ -274,10 +274,10 @@ ECHO . ) ) ELSE IF "%TARGET_CPU%" == "x64" ( + SET "FxTools=%FrameworkDir64%\%FrameworkVersion%;%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework64\v3.5;%windir%\Microsoft.NET\Framework\v3.5;" + SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools\IA64;%WindowsSdkDir%Bin\IA64;%WindowsSdkDir%Bin;" IF EXIST "%VCTools%\x86_amd64\cl.exe" ( SET "VCTools=%VCTools%\x86_amd64;%VCTools%\VCPackages;" - SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools\IA64;%WindowsSdkDir%Bin\IA64;%WindowsSdkDir%Bin;" - SET "FxTools=%FrameworkDir64%\%FrameworkVersion%;%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework64\v3.5;%windir%\Microsoft.NET\Framework\v3.5;" ) ELSE ( SET VCTools= ECHO The VC compilers are not currently installed. @@ -285,10 +285,10 @@ ECHO . ) ) ELSE IF "%TARGET_CPU%" == "x86" ( + SET "FxTools=%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework\v3.5;" + SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools;%WindowsSdkDir%Bin;" IF EXIST "%VCTools%\cl.exe" ( SET "VCTools=%VCTools%;%VCTools%\VCPackages;" - SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools;%WindowsSdkDir%Bin;" - SET "FxTools=%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework\v3.5;" ) ELSE ( SET VCTools= ECHO The x86 compilers are not currently installed. @@ -298,10 +298,10 @@ ) ) ELSE IF "%CURRENT_CPU%"=="x86" ( IF "%TARGET_CPU%" == "x64" ( + SET "FxTools=%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework\v3.5;" + SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools;%WindowsSdkDir%Bin;" IF EXIST "%VCTools%\x86_amd64\cl.exe" ( SET "VCTools=%VCTools%\x86_amd64;%VCTools%\VCPackages;" - SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools;%WindowsSdkDir%Bin;" - SET "FxTools=%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework\v3.5;" ) ELSE ( SET VCTools= ECHO The x64 cross compilers are not currently installed. @@ -309,10 +309,10 @@ ECHO . ) ) ELSE IF "%TARGET_CPU%" == "IA64" ( + SET "FxTools=%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework\v3.5;" + SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools;%WindowsSdkDir%Bin;" IF EXIST "%VCTools%\x86_IA64\cl.exe" ( SET "VCTools=%VCTools%\x86_IA64;%VCTools%;%VCTools%\VCPackages;" - SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools;%WindowsSdkDir%Bin;" - SET "FxTools=%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework\v3.5;" ) ELSE ( SET VCTools= ECHO The IA64 compilers are not currently installed. @@ -320,10 +320,10 @@ ECHO . ) ) ELSE IF "%TARGET_CPU%" == "x86" ( + SET "FxTools=%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework\v3.5;" + SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools;%WindowsSdkDir%Bin;" IF EXIST "%VCTools%\cl.exe" ( SET "VCTools=%VCTools%;%VCTools%\VCPackages;" - SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools;%WindowsSdkDir%Bin;" - SET "FxTools=%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework\v3.5;" ) ELSE ( SET VCTools= ECHO The x86 compilers are not currently installed. x86-x86 @@ -331,15 +331,17 @@ ECHO . ) ) -) ELSE IF EXIST "%VCTools%\cl.exe" ( - SET "VCTools=%VCTools%;%VCTools%\VCPackages;" - SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools;%WindowsSdkDir%Bin;" - SET "FxTools=%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework\v3.5;" ) ELSE ( - SET VCTools= - ECHO The x86 compilers are not currently installed. default - ECHO Please go to Add/Remove Programs to update your installation. - ECHO . + SET "FxTools=%FrameworkDir32%%FrameworkVersion%;%windir%\Microsoft.NET\Framework\v3.5;" + SET "SdkTools=%WindowsSdkDir%Bin\NETFX 4.0 Tools;%WindowsSdkDir%Bin;" + IF EXIST "%VCTools%\cl.exe" ( + SET "VCTools=%VCTools%;%VCTools%\VCPackages;" + ) ELSE ( + SET VCTools= + ECHO The x86 compilers are not currently installed. default + ECHO Please go to Add/Remove Programs to update your installation. + ECHO . + ) ) :: --------------------------------------------------------------------------------------------