0

I want to execute msbuild.exe command from winform c# on button click

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"); 

I have updated my code used following code to execute msbuild it is working but screen closed out once all execute , I should have to see screen open

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();
Tassisto
  • 9,877
  • 28
  • 100
  • 157
Neo
  • 15,491
  • 59
  • 215
  • 405
  • http://stackoverflow.com/questions/17495170/executing-custom-commands-from-command-prompt-in-winform-c-sharp – Roy Miloh Sep 28 '15 at 15:28
  • duplicate questions are similar but my code is different please check updated question – Neo Sep 28 '15 at 16:52

1 Answers1

1
  System.Diagnostics.Process.Start(@"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe");
ElectricRouge
  • 1,239
  • 3
  • 22
  • 33
  • unable to build solution using above can you please more elaborate ? – Neo Sep 28 '15 at 16:19
  • dont know how that can be an acceptable answer because of the hardcoded path. How about that: **1.** add Reference of "Microsoft.Build.Utilities.Core" **2.** var path = ToolLocationHelper.GetPathToBuildTools(ToolLocationHelper.CurrentToolsVersion).ToString(); – Ben jamin Sep 12 '17 at 06:34