問題描述
我正在嘗試以編程方式執行 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!