internal void Build(Project proj, bool consoleBuild, string targetToBuild, string title = "") { if (!string.IsNullOrEmpty(title)) { this.windowTitle = title; } if (string.IsNullOrEmpty(targetToBuild)) { this.windowTitle = new FileInfo(proj.FullPath).Name; } if (consoleBuild) { string targets = targetToBuild; if (!string.IsNullOrEmpty(targets)) { targets = "/t:" + targets; } else if (this.treeviewTargets.Items.Count > 0) { targets = (from object target in this.treeviewTargets.Items select target as MSBuildTarget).Aggregate(targets, (current, t) => current + (t.Name + ";")); targets = "/t:" + targets.Remove(targets.LastIndexOf(';'), 1); } string appStartPath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); string args = string.Format(CultureInfo.CurrentCulture, "\"{0}\" {1} {2}", proj.FullPath, targets, this.TextBoxParameters.Text); using (FileStream fileStream = File.Open(appStartPath + @"\wrap.bat", FileMode.Create)) { using (StreamWriter streamWriter = new StreamWriter(fileStream)) { streamWriter.WriteLine(@"TITLE " + this.windowTitle); streamWriter.WriteLine(@"ECHO Off"); streamWriter.Write(this.TextBoxPreExecute.Text); streamWriter.WriteLine(); streamWriter.WriteLine(@"msbuild.exe " + args); if (Settings.Default.PauseConsoleAfterExecution) { streamWriter.WriteLine(@"pause"); } } } // configure the process we need to run Process buildwrapper = new Process { StartInfo = { FileName = appStartPath + @"\wrap.bat", UseShellExecute = false, Arguments = args } }; // start the process buildwrapper.Start(); } else { try { MSBuildExplorerLogger logger = new MSBuildExplorerLogger { Verbosity = LoggerVerbosity.Diagnostic }; logger.OnMessage += this.LogBuildMessage; if (this.treeviewTargets.Items.Count > 0) { string[] targets = new string[this.treeviewTargets.Items.Count]; int i = 0; foreach (var target in this.treeviewTargets.Items) { MSBuildTarget t = target as MSBuildTarget; if (t != null) { targets[i] = t.Name; } i++; } System.Collections.Generic.IEnumerable<ILogger> tt = new ILogger[] { logger }; proj.Build(targets, tt); } else { proj.Build(logger); } // this.TextBoxOutput.Document = this.flowDoc; } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
internal void Build(Project proj, bool consoleBuild, string targetToBuild, string title = "") { if (!string.IsNullOrEmpty(title)) { this.windowTitle = title; } if (string.IsNullOrEmpty(targetToBuild)) { this.windowTitle = new FileInfo(proj.FullPath).Name; } if (consoleBuild) { string targets = targetToBuild; if (!string.IsNullOrEmpty(targets)) { targets = "/t:" + targets; } else if (this.treeviewTargets.Items.Count > 0) { targets = (from object target in this.treeviewTargets.Items select target as MSBuildTarget).Aggregate(targets, (current, t) => current + (t.Name + ";")); targets = "/t:" + targets.Remove(targets.LastIndexOf(';'), 1); } string appStartPath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); string args = string.Format(CultureInfo.CurrentCulture, "\"{0}\" {1} {2}", proj.FullPath, targets, this.TextBoxParameters.Text); using (FileStream fileStream = File.Open(appStartPath + @"\wrap.bat", FileMode.Create)) { using (StreamWriter streamWriter = new StreamWriter(fileStream)) { streamWriter.WriteLine(@"TITLE " + this.windowTitle); streamWriter.WriteLine(@"ECHO Off"); streamWriter.Write(this.TextBoxPreExecute.Text); streamWriter.WriteLine(); streamWriter.WriteLine(@"msbuild.exe " + args); if (Settings.Default.PauseConsoleAfterExecution) { streamWriter.WriteLine(@"pause"); } } } // configure the process we need to run Process buildwrapper = new Process { StartInfo = { FileName = appStartPath + @"\wrap.bat", UseShellExecute = false, Arguments = args } }; // start the process buildwrapper.Start(); } else { try { MSBuildExplorerLogger logger = new MSBuildExplorerLogger { Verbosity = LoggerVerbosity.Diagnostic }; logger.OnMessage += this.LogBuildMessage; if (this.treeviewTargets.Items.Count > 0) { string[] targets = new string[this.treeviewTargets.Items.Count]; int i = 0; foreach (var target in this.treeviewTargets.Items) { MSBuildTarget t = target as MSBuildTarget; if (t != null) { targets[i] = t.Name; } i++; } System.Collections.Generic.IEnumerable <ILogger> tt = new ILogger[] { logger }; proj.Build(targets, tt); } else { proj.Build(logger); } // this.TextBoxOutput.Document = this.flowDoc; } catch (Exception ex) { MessageBox.Show(ex.Message); } } }