以编程方式运行 MSBuild
我试图以编程方式执行 MSBuild,但无法执行以下命令:
string command = string.Format(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe ""{0}\{1}.csproj""", _args.ProjectPath, _args.ProjectName);
字符串呈现为:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe "C:\...\TestResults\Foo 2011-08-31 16_29_40\Out\Foo\solutionName\projectName\projectName.csproj"
然后我使用 new ProcessStartInfo(command)。问题似乎是 Foo 和 2011 之间的空格。我得到以下输出:
MSBUILD : error MSB1008: Only one project can be specified.
Switch: 16_29_40\Out\Foo\solutionName\projectName\projectName.csproj
How do I pass in the project file to MSBuild?
I am trying to execute MSBuild programmatically and can't execute the following command:
string command = string.Format(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe ""{0}\{1}.csproj""", _args.ProjectPath, _args.ProjectName);
The string gets rendered as:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe "C:\...\TestResults\Foo 2011-08-31 16_29_40\Out\Foo\solutionName\projectName\projectName.csproj"
I then use new ProcessStartInfo(command). The problem seems to be the space between Foo and 2011. I get the following output:
MSBUILD : error MSB1008: Only one project can be specified.
Switch: 16_29_40\Out\Foo\solutionName\projectName\projectName.csproj
How do I pass in the project file to MSBuild?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议 stronlgy 通过
Microsoft 中的类/接口走官方路线.Build
命名空间。微软到处都使用这个,所以这应该很重要......特别是。类
Microsoft.Build.Execution.BuildManager
和 SingletonMicrosoft.Build.Execution.BuildManager.DefaultBuildManager
是您运行构建任务所需的...源代码示例:I would recommend stronlgy to go the official route via classes/interfaces in
Microsoft.Build
namespace. Microsoft uses this all over the place, so this should count for something...Esp. the class
Microsoft.Build.Execution.BuildManager
and the SingletonMicrosoft.Build.Execution.BuildManager.DefaultBuildManager
is what you are after to run a build task... source code examples:这是一个带有简单记录器的完整工作示例。
构建解决方案:
以及 logger 类(强烈源自此 MSDN 记录器):
Here a full working example with a simple logger.
To build a solution:
And the logger class (strongly derived of this MSDN logger):
您需要使用
ProcessStartInfo
的Arguments
属性来传递参数。例如
,但是,对于 MSBuild,您应该使用 Yahia 提到的 的官方方法。
You need to use the
Arguments
property of theProcessStartInfo
to pass parameters.e.g.
However, for MSBuild specifically you should use the official method as Yahia mentions.