【问题标题】:how to execute msbuild.exe command using winform c#? [duplicate]如何使用 winform c# 执行 msbuild.exe 命令? [复制]
【发布时间】:2015-09-28 15:26:20
【问题描述】:

我想在单击按钮时从 winform c# 执行 msbuild.exe 命令

private void button2_Click(object sender, EventArgs e)
{
    // get the reg key
    RegistryKey regKey;
    regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\MSBuild\ToolsVersions\4");

    // get the CurrentInstallFolder
    string msBuildToolsPath = (string)regKey.GetValue("MSBuildToolsPath"); 

我已经更新了我的代码,使用以下代码来执行 msbuild 它正在工作,但是一旦全部执行,屏幕就会关闭,我应该看到屏幕打开

var solutionFile = item.ToString();
var msbuildPath = msBuildToolsPath;

var startInfo = new ProcessStartInfo()
{
    CreateNoWindow = true,
    Arguments = String.Format("\"{0}\" /nologo", solutionFile),
        FileName = Path.Combine(msbuildPath, "msbuild.exe")
};

var proc = Process.Start(startInfo);
proc.WaitForExit();

【问题讨论】:

标签: c# .net winforms msbuild


【解决方案1】:
  System.Diagnostics.Process.Start(@"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe");

【讨论】:

  • 无法使用上述方法构建解决方案,您能否详细说明一下?
  • 不知道这是一个可以接受的答案,因为路径是硬编码的。怎么样:1. 添加“Microsoft.Build.Utilities.Core”参考2. var path = ToolLocationHelper.GetPathToBuildTools(ToolLocationHelper.CurrentToolsVersion).ToString();
猜你喜欢
  • 2015-06-28
  • 2013-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-08
  • 2019-05-04
  • 2018-10-16
相关资源
最近更新 更多