我正在我们的 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 更新,或者是时候放弃并开始破解系统了路径?
要在
命令提示符中启用
msbuild
,您只需将计算机上msbuild.exe
安装的目录添加到PATH
环境变量即可。
您可以通过以下方式访问环境变量:
PATH
C:\Windows\Microsoft.NET\Framework\v4.0.30319
MSBuild 现在作为 Visual Studio 的一部分安装。
对于VS2015 路径是 %ProgramFiles(x86)%\MSBuild\14.0\Bin
VS2017 路径是 %ProgramFiles(x86)%\Microsoft Visual Studio\2017\<YOUR_VS_EDITION>\MSBuild\15.0\Bin
VS2019,路径是 %ProgramFiles(x86)%\Microsoft Visual Studio\2019\<YOUR_VS_EDITION>\MSBuild\Current\Bin
VS2022,路径是 %ProgramFiles%\Microsoft Visual Studio\2022\<YOUR_VS_EDITION>\MSBuild\Current\Bin
<YOUR_VS_EDITION>
与您安装的 Visual Studio 版本匹配,即
Preview
、
Community
、
Professional
、
Enterprise
。
Visual Studio 2013
开始,
MSbuild
作为 Visual Studio 的一部分。早些时候,MSBuild 作为 的一部分安装。 NET 框架。
MSBuild直接安装在%ProgramFiles%下。因此,根据 Visual Studio 的版本,MSBuild 的路径可能会有所不同。
对于Visual Studio 2015
,
MSBuild
的路径是
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
对于Visual Studio 15 Preview
,
MSBuild
的路径是
"%ProgramFiles(x86)%\MSBuild\15.0\Bin\MSBuild.exe"
此外,还添加了一些新的 MSBuild 属性,并修改了一些属性。
欲了解更多信息请看更新1:VS 2017 随着
Visual Studio 2017 的发布,MSBuild 的位置再次发生变化。现在安装目录位于%ProgramFiles(x86)%\Microsoft Visual Studio\2017\[VS Edition]\MSBuild\15.0\Bin\
下。因为我有企业版,所以我的机器的 MSBuild 位置是
"%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSbuild.exe"
更新2:VS 2019路径是
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MsBuild.exe
。
而不是“cmd”将自动设置 msbuild 的路径,而无需将其添加到环境变量中。
CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319
msbuild C:\Users\mmaratt\Desktop\BladeTortoise\build\ALL_BUILD.vcxproj
PAUSE
EXIT
C:\Program Files (x86)\Microsoft Visual Studio�9\Preview\MSBuild\Current\Bin\MSBuild.exe
我想 2019 年正式版本的流程会类似。
C:\Program Files (x86)\MSBuild .0\Bin
C:\Program Files\Microsoft Visual Studio�2\Preview\MSBuild\Current
我想 2022 年正式版本的流程会类似。
%ProgramFiles%\Microsoft Visual Studio�2\Community\MSBuild\Current\Bin
如果您的 Windows 中没有此路径,请通过搜索 %ProgramFiles% 目录找到类似的路径
SetEnv.cmd
脚本会在向
cl.exe
添加任何条目之前在各个位置检查 PATH
。因此,如果未安装本机 C 编译器,即使安装了 .NET 工具,它也无法添加任何内容。解决方法是运行 Windows SDK 7.1 安装程序并安装 SDK 的本机 C++ 工具链。真正的解决方法是将以下补丁应用到
SetEnv.cmd
<SDK install dir>\Bin\SetEnv.cmd
下。这还将修复位于
<SDK install dir>\Bin
和子文件夹中的其他工具的丢失路径。--- 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 .
+ )
)
:: --------------------------------------------------------------------------------------------