BuildResult IProjectBuildHandler.Build(BuildItemNode buildItem) { _isBuildInProgress = true; ProjectNode project = buildItem.Parent.Parent.Parent; BuildConfigurationNode configuration = buildItem.Parent; string solutionFilePath = buildItem.GetFullPath(); string workingDirectory = Path.GetDirectoryName(project.FileName); BuildResult result = new BuildResult(); _currentBuildProcess = new Process(); _currentBuildProcess.StartInfo.FileName = _msBuildPath; if (configuration.PerformReBuild) { PerformClean(buildItem); } _currentBuildProcess.StartInfo.Arguments = string.Format("\"{0}\" /p:Configuration={1} /verbosity:{2}", solutionFilePath, GetConfiguration(configuration.Configuration, buildItem), configuration.Verbosity); _currentBuildProcess.StartInfo.RedirectStandardOutput = true; _currentBuildProcess.StartInfo.UseShellExecute = false; _currentBuildProcess.EnableRaisingEvents = true; _currentBuildProcess.OutputDataReceived += (o, e) => { string text = e.Data; if (string.IsNullOrWhiteSpace(e.Data)) { return; } text = text.Trim(); BuildInfoItem item = new BuildInfoItem() { Text = text }; item.Level = BuildInfoItemLevel.Trace; if (text.Contains("->")) { item.Level = BuildInfoItemLevel.Info; } if (text.Contains("error")) { item.Level = BuildInfoItemLevel.Error; } if (text.Contains("warning")) { item.Level = BuildInfoItemLevel.Warning; } result.Items.Add(item); }; _currentBuildProcess.Start(); _currentBuildProcess.BeginOutputReadLine(); _currentBuildProcess.WaitForExit(); _currentBuildProcess = null; _isBuildInProgress = false; return result; }
private void PerformClean(BuildItemNode buildItem) { string solutionFilePath = buildItem.GetFullPath(); Process cleanProcess = new Process(); cleanProcess.StartInfo.FileName = _msBuildPath; cleanProcess.StartInfo.Arguments = string.Format("\"{0}\" /t:Clean", solutionFilePath); cleanProcess.StartInfo.RedirectStandardOutput = true; cleanProcess.StartInfo.UseShellExecute = false; cleanProcess.Start(); cleanProcess.WaitForExit(); }