public Task <Build> BuildAndGetResult(BuildProgress progress) { var msbuildExe = SettingsService.GetMSBuildExe(); var postfixArguments = GetPostfixArguments(); // the command line we pass to Process.Start doesn't need msbuild.exe var commandLine = $"{projectFilePath.QuoteIfNeeded()} {customArguments} {postfixArguments}"; // the command line we display to the user should contain the full path to msbuild.exe progress.MSBuildCommandLine = $"{msbuildExe.QuoteIfNeeded()} {commandLine}"; return(System.Threading.Tasks.Task.Run(() => { try { var arguments = commandLine; var processStartInfo = new ProcessStartInfo(msbuildExe, arguments); processStartInfo.WorkingDirectory = Path.GetDirectoryName(projectFilePath); var process = Process.Start(processStartInfo); process.WaitForExit(); var logFilePath = Path.Combine(currentDirectory, "msbuild.binlog"); var build = Serialization.Read(logFilePath); //File.Delete(logFilePath); //var projectImportsZip = Path.ChangeExtension(logFilePath, ".ProjectImports.zip"); //if (File.Exists(projectImportsZip)) //{ // File.Delete(projectImportsZip); //} return build; } catch (Exception ex) { ex = ExceptionHandler.Unwrap(ex); var build = new Build(); build.Succeeded = false; build.AddChild(new Message() { Text = "Exception occurred during build:" }); build.AddChild(new Error() { Text = ex.ToString() }); return build; } })); }
public Task <Build> BuildAndGetResult(BuildProgress progress) { var msbuildExe = SettingsService.GetMSBuildExe(); var prefixArguments = GetPrefixArguments(projectFilePath); var postfixArguments = GetPostfixArguments(); // the command line we display to the user should contain the full path to msbuild.exe var commandLine = $@"{prefixArguments} {customArguments} {postfixArguments}"; progress.MSBuildCommandLine = commandLine; // the command line we pass to Process.Start doesn't need msbuild.exe commandLine = $@"""{projectFilePath}"" {customArguments} {postfixArguments}"; return(System.Threading.Tasks.Task.Run(() => { try { var arguments = commandLine; var processStartInfo = new ProcessStartInfo(msbuildExe, arguments); processStartInfo.WorkingDirectory = Path.GetDirectoryName(projectFilePath); var process = Process.Start(processStartInfo); process.WaitForExit(); var build = Serialization.Read(logFilePath); File.Delete(logFilePath); return build; } catch (Exception ex) { var build = new Build(); build.Succeeded = false; build.AddChild(new Message() { Text = "Exception occurred during build:" }); build.AddChild(new Error() { Text = ex.ToString() }); return build; } })); }
public static string GetPrefixArguments(string projectFilePath) { var msbuildExe = SettingsService.GetMSBuildExe(); return($@"""{msbuildExe}"" ""{projectFilePath}"""); }