/// <summary> /// Builds the specified data. /// </summary> public static void Build(MSBuildData data) { var msbuildPath = GetMsBuildExePath(); var arguments = new StringBuilder(); arguments.Append(data.ProjectFilePath); if (data.ProjectFilePath.EndsWith(".sln")) { arguments.Append(" /p:Configuration=Debug /p:Platform=\"Any CPU\""); } var startInfo = new ProcessStartInfo(msbuildPath) { Arguments = arguments.ToString(), ErrorDialog = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true }; var process = Process.Start(startInfo); if (process == null) { throw new InvalidOperationException(nameof(process)); } process.WaitForExit(6000); data.BuildOutput = process.StandardOutput.ReadToEnd(); data.StandardError = process.StandardError.ReadToEnd(); var hasError = process.ExitCode > 0; if (hasError) { data.BuildError = new InvalidOperationException(data.StandardError + data.BuildOutput); } }
/// <summary> /// Gets the content of the bat file. /// </summary> public static string GetBatFileContent(MSBuildData data) { var sb = new StringBuilder(); var msBuildExePath = GetMsBuildExePath(); // ReSharper disable once ExpressionIsAlwaysNull var msBuildExeDirectory = Path.GetDirectoryName(msBuildExePath) + Path.DirectorySeparatorChar; sb.AppendLine($"SET PATH={msBuildExeDirectory}"); sb.AppendLine($@"SET SolutionPath={data.ProjectFilePath}"); if (data.ProjectFilePath.EndsWith(".sln")) { sb.AppendLine(@"MSbuild %SolutionPath% /p:Configuration=Debug /p:Platform=""Any CPU"""); } else { sb.AppendLine(@"MSbuild %SolutionPath%"); } return(sb.ToString()); }