|
using System;
namespace VsBuilderHelper
{
/// <summary>
/// Summary description for Builder.
/// </summary>
public class Builder
{
#region members
public string errorLog;
#endregion
#region constructors
public Builder()
{
//
// TODO: Add constructor logic here
//
}
#endregion
#region public interface
[STAThread]
public static int Main(string[] args)
{
if (args.GetLength(0) == 0)
{
System.Console.WriteLine("Invalid swtiches used. Syntax is ");
System.Console.WriteLine(@"VsBuilderHelper.exe c:\mysolution.sln debug");
System.Console.WriteLine("Hit enter to exit...");
System.Console.Read();
return 1;
}
Builder b = new Builder();
return b.Build(args.GetValue(0).ToString(), args.GetValue(1).ToString());
}
public int Build(string solutionFile, string solutionConfig)
{
// get temp logfile path
string logFileName = System.IO.Path.GetTempFileName();
// populate process environment
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName =@"devenv.exe";
psi.ErrorDialog = true;
psi.Arguments = "\"" +solutionFile +"\"" + @" /rebuild "+ solutionConfig + " /out " + logFileName;
// start process
System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
// instruct process to wait for exit
p.WaitForExit();
// get return code
int exitCode = p.ExitCode;
// free process resources
p.Close();
// if there was a build error, display build log to console
if (exitCode != 0)
{
System.IO.TextReader reader = System.IO.File.OpenText(logFileName);
errorLog = reader.ReadToEnd();
reader.Close();
//
System.Console.WriteLine(errorLog);
System.Console.WriteLine("Hit enter to abort...");
System.Console.Read();
}
// delete temp logfile
System.IO.File.Delete(logFileName);
// return process exit code
return exitCode;
}
#endregion
#region internals
#endregion
#region events
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.