If you want to build a Microsoft Visual Studio solution file and show the output during build, you can use the following code:

 

/// <summary>
/// Rebuilds the Microsoft Visual Studio Solution in the given configuration.
///     - Shows build output during build
/// </summary>
public void Rebuild()
{
    string logFilePath = "build.log";
    using (Process process = Process.Start(
        @"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe", 
        string.Format(@"""{0}"" /Rebuild Release /out {1}", @"C:\Projects\Main.sln", logFilePath)))
    {
        using (FileStream fs = new FileStream(  logFilePath, 
                                                FileMode.Open, 
                                                FileAccess.Read, 
                                                FileShare.ReadWrite))
        {
            using (StreamReader sr = new StreamReader(fs))
            {
                while (!process.HasExited)
                {
                    while (!sr.EndOfStream)
                    {
                        Console.WriteLine(sr.ReadLine());
                    }
                    Thread.Sleep(1000);
                }
            }
        }
    }
    Console.WriteLine("Rebuild completed");
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.