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();
2
  • stackoverflow.com/questions/17495170/… Commented Sep 28, 2015 at 15:28
  • duplicate questions are similar but my code is different please check updated question Commented Sep 28, 2015 at 16:52

1 Answer 1

1
  System.Diagnostics.Process.Start(@"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe");
Sign up to request clarification or add additional context in comments.

2 Comments

unable to build solution using above can you please more elaborate ?
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();

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.