以编程方式运行 MSBuild
- 作者: 天高云淡33103181
- 来源: 51数据库
- 2023-02-13
问题描述
我正在尝试以编程方式执行 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 记录构建消息
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源