首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何编译.net解决方案并获得输出?

问如何编译.net解决方案并获得输出?
EN

Stack Overflow用户
提问于 2016-06-09 00:39:27
回答 1查看 539关注 0票数 0

我正在做一些自动化的工作。我有一个将编译.net解决方案的批处理文件。我希望自动化这一点,但我被卡住了。

原始文件:

代码语言:javascript
复制
"B:\Microsoft Visual Studio 9.0\Common7\IDE\devenv" "My_Types\My_Types.sln" /build >> ..\Output\Build.txt

我可以让它与修改后的文件一起工作:

代码语言:javascript
复制
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)

修改后的文件

代码语言:javascript
复制
   "B:\Microsoft Visual Studio 9.0\Common7\IDE\devenv" "C:\Code\Intuitive Projects\My_Types\My_Types.sln" /build

但是我不能让下一步工作。这与争论有关。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2016-09-03 11:17:06

Visual Studio不是命令行程序,因此它不能输出到标准输出。但是,使用/Out "LogFilename.txt“,您可以将其输出到日志文件中。例如:

代码语言:javascript
复制
    "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位版本中。它输出的示例告诉您需要了解的所有内容:

代码语言:javascript
复制
    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。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37708252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档