从命令提示符运行MSBuild

Bes*_*seB -1 python msbuild command-prompt

如果我打开命令提示符,然后键入msbuild或/ msbuild,然后键入路径文件,则表示

'msbuild' is not recognized as an internal or external command, operable program or batch file.'

但是,当我在Visual Studios命令提示符中运行相同的行时,它会起作用。有人知道这是为什么吗?

这是我的python脚本,用于通过命令提示符运行MSBuild

import subprocess
filename="C:\Users\bb\Documents\bb\Code\VisualStudio\tree.ProEAPI.UnitTests\tree.ProEAPI.UnitTests.vbproj"
p = subprocess.Popen(['C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe', filename], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
    print line,
retval = p.wait()
Run Code Online (Sandbox Code Playgroud)

Ste*_*nds 5

当您启动Visual Studio命令提示符时,它将在“路径”环境变量中添加一些其他位置-碰巧包括MSBuild的位置。

有趣的旁注-您可以批量使用“ where”命令来查找应用程序的路径。例如,在Visual Studio命令行中运行“ where msbuild”将输出以下内容:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC>where msbuild
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
C:\Windows\Microsoft.NET\Framework64\v3.5\MSBuild.exe
Run Code Online (Sandbox Code Playgroud)

但是在标准命令提示符下,输出以下内容:

C:\Users\stephen.edmonds>where msbuild
INFO: Could not find files for the given pattern(s).
Run Code Online (Sandbox Code Playgroud)

您可以使用“设置路径”命令查看路径环境变量的当前值。