Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从命令提示符运行MSBuild_Python_Msbuild_Command Prompt - Fatal编程技术网

Python 从命令提示符运行MSBuild

Python 从命令提示符运行MSBuild,python,msbuild,command-prompt,Python,Msbuild,Command Prompt,如果打开命令提示符,键入msbuild或/msbuild,后跟路径文件,则会显示 “msbuild”未被识别为内部或外部命令、可操作程序或批处理 文件。' 但是,当我在visual Studio命令提示符下运行相同的行时,它会工作。。有人知道这是为什么吗 下面是通过命令提示符运行MSBuild的python脚本 import subprocess filename="C:\Users\bb\Documents\bb\Code\VisualStudio\tree.ProEAPI.UnitTests

如果打开命令提示符,键入msbuild或/msbuild,后跟路径文件,则会显示

“msbuild”未被识别为内部或外部命令、可操作程序或批处理
文件。
'

但是,当我在visual Studio命令提示符下运行相同的行时,它会工作。。有人知道这是为什么吗

下面是通过命令提示符运行MSBuild的python脚本

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

当启动Visual Studio命令提示符时,它会向“path”环境变量添加一些其他位置-这恰好包括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
C:\Users\stephen.edmonds>where msbuild
INFO: Could not find files for the given pattern(s).
但在标准命令提示符中,输出以下内容:

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
C:\Users\stephen.edmonds>where msbuild
INFO: Could not find files for the given pattern(s).

您可以使用命令“set path”查看path环境变量的当前值,因为命令pompt缺少path环境变量中msbuild.exe的位置。对于.NET 4,通常为C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319。请尝试在计算机管理控制台或在命令提示下进行设置:

set path=%path%;C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\ 

然后重试msbuild。

当我直接将整个文件路径添加到msbuild.exe时,请在命令提示符下添加文件路径,该命令会起作用。但是,当我将相同的内容复制到python脚本中时,它仍然无法工作,它会发出相同的消息。我将添加对python代码的编辑。