Saturday 22 September 2012

Build .Net Project Solution programatically using C#

private void btnBuild_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = "";
            string[] solutions = GetSolutions();
            foreach (string solution in solutions)
            {
                var startinfo = new ProcessStartInfo();
                startinfo.FileName = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe";
                startinfo.Arguments = "/t:rebuild  /p:Configuration=Debug " + solution;
                startinfo.RedirectStandardError = true;

                startinfo.RedirectStandardOutput = true;
                startinfo.UseShellExecute = false;

                Process build = Process.Start(startinfo);

                //string error = build.StandardError.ReadToEnd();
                string output = build.StandardOutput.ReadToEnd();

                build.WaitForExit();

                richTextBox1.Text = output;

             }
        }


private string[] GetSolutions()
        {
            string[] filePaths = Directory.GetFiles(txtLoc.Text);

            return filePaths;
        }

No comments:

Post a Comment

How to find a string within a jQuery or javascript string

Sometimes, you required to find a the existence of a small string with in a string. This article will  demonstarte , how could you do by...