我正在做一些自动化的工作。我有一个将编译.net解决方案的批处理文件。我希望自动化这一点,但我被卡住了。
原始文件:
"B:\Microsoft Visual Studio 9.0\Common7\IDE\devenv" "My_Types\My_Types.sln" /build >> ..\Output\Build.txt我可以让它与修改后的文件一起工作:
Compile = New Process()
With Compile.StartInfo
.UseShellExecute = False
.RedirectStandardOutput = True
.FileName = """C:\Code\Intuitive Projects\Build Test.bat"""
End With
bSuccess = Compile.Start()
strOutput = Compile.StandardOutput.ReadToEnd()
Compile.WaitForExit()
MsgBox(strOutput)修改后的文件
"B:\Microsoft Visual Studio 9.0\Common7\IDE\devenv" "C:\Code\Intuitive Projects\My_Types\My_Types.sln" /build但是我不能让下一步工作。这与争论有关。
Compile = New Process()
With Compile.StartInfo
.UseShellExecute = False
.RedirectStandardOutput = True
.FileName = "b:\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
'.Arguments = "C:\Code\Intuitive Projects\My_Types\My_Types.sln /build" 'Does nothing
'.Arguments = """C:\Code\Intuitive Projects\My_Types\My_Types.sln"" /build" 'Does nothing
'.Arguments = """""C:\Code\Intuitive Projects\My_Types\My_Types.sln /build""""" 'Opens visual studio and parses the path as two files.
'.Arguments = """""""C:\Code\Intuitive Projects\Projects\My_Types\My_Types.sln"" /build""""" 'Opend the file but I get a message saying files can not be found but there are no files in the list.
'.Arguments = """""""C:\Code\Intuitive Projects\Projects\My_Types\My_Types.sln"" ""/build""""""" 'Tried this because I couldnt think of anything else, fails to find the file "/build"
End With
bSuccess = Compile.Start()
strOutput = Compile.StandardOutput.ReadToEnd()
Compile.WaitForExit()
MsgBox(strOutput)发布于 2016-09-03 11:17:06
Visual Studio不是命令行程序,因此它不能输出到标准输出。但是,使用/Out "LogFilename.txt“,您可以将其输出到日志文件中。例如:
"C:\Code\Intuitive Projects\My_Types\My_Types.sln" /build "Release|Any CPU" /Out C:\Temp\TempLog.txt您可以打开并解析日志文件。
也就是说,如果可以的话,使用MSBuild.exe而不是DevEnv.exe。MSBuild位于C:\Windows\Microsoft.NET\Framework\v中,或者位于C:\Windows\Microsoft.NET\Framework64\v中的64位版本中。它输出的示例告诉您需要了解的所有内容:
MSBuild MyApp.sln /t:Rebuild /p:Configuration=Release
MSBuild MyApp.csproj /t:Clean
/p:Configuration=Debug;TargetFrameworkVersion=v3.5正如您所期望的那样,它输出到标准输出/标准错误。唯一奇怪的是,如果在使用/p参数发送的某个定义中包含括号或美元符号,MSBuild将以非常奇怪的方式崩溃。在这些情况下,您应该使用DevEnv.exe。
或者,您也可以通过编程方式调用MSBuild,但是这会稍微复杂一些。请参阅Microsoft.Build.Execution.BuildManager上的信息来实现这一点。或者,如果您想获得非常低的级别,请查看CodeDOM。
https://stackoverflow.com/questions/37708252
复制相似问题