2016-06-08 47 views
0

我正在进行一些自动化。我有一个批处理文件,可以编译.net解决方案。我希望自动化,但我卡住了。如何编译.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) 
+5

'msbuild foo.sln' –

+0

您使用的是... PowerShell? VB.NET?你没有语言标签,这将有助于指导答复者。 –

+0

我不知道有另一种方式来编译C#或VB。添加了标签。 – Joe

回答

0

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

相关问题