以编程方式运行 MSBuild

Running MSBuild programmatically(以编程方式运行 MSBuild)
本文介绍了以编程方式运行 MSBuild的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试以编程方式执行 MSBuild,但无法执行以下命令:

I am trying to execute MSBuild programmatically and can't execute the following command:

string command = string.Format(@"C:WindowsMicrosoft.NETFrameworkv4.0.30319msbuild.exe  ""{0}{1}.csproj""", _args.ProjectPath, _args.ProjectName);

字符串被渲染为:

C:WindowsMicrosoft.NETFrameworkv4.0.30319msbuild.exe  "C:...TestResultsFoo 2011-08-31 16_29_40OutFoosolutionNameprojectNameprojectName.csproj"

然后我使用新的 ProcessStartInfo(command).问题似乎是 Foo 和 2011 之间的空间.我得到以下输出:

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_40OutFoosolutionNameprojectNameprojectName.csproj

如何将项目文件传递给 MSBuild?

How do I pass in the project file to MSBuild?

推荐答案

我会推荐 stronlgy 通过 Microsoft.Build 命名空间.微软到处都在使用它,所以这应该很重要......

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...

特别是.类 Microsoft.Build.Execution.BuildManager 和 Singleton Microsoft.Build.Execution.BuildManager.DefaultBuildManager 是您运行构建任务所需要的...源代码示例:

Esp. the class Microsoft.Build.Execution.BuildManager and the Singleton Microsoft.Build.Execution.BuildManager.DefaultBuildManager is what you are after to run a build task... source code examples:

  • http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/ec95c513-f972-45ad-b108-5fcfd27f39bc/
  • 使用 MSBuild 4.0 记录构建消息

这篇关于以编程方式运行 MSBuild的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to know if a field is numeric in Linq To SQL(如何在 Linq To SQL 中知道字段是否为数字)
Extract sql query from LINQ expressions(从 LINQ 表达式中提取 sql 查询)
LINQ Where in collection clause(LINQ Where in collection 子句)
Orderby() not ordering numbers correctly c#(Orderby() 没有正确排序数字 c#)
Why do I get quot;error: ... must be a reference typequot; in my C# generic method?(为什么我会收到“错误:...必须是引用类型?在我的 C# 泛型方法中?)
Strange LINQ Exception (Index out of bounds)(奇怪的 LINQ 异常(索引越界))