private void button1_Click(object sender, RoutedEventArgs e) { try { this.Cursor = Cursors.Wait; string codeBaseRootPath = txtRootFolder.Text; if (!System.IO.Directory.Exists(codeBaseRootPath)) { MessageBox.Show("The code base root folder does not exist or is invalid.", "Folder Does Not Exist", MessageBoxButton.OK, MessageBoxImage.Error); return; } BuildSequencer bs = new BuildSequencer(); bs.Load(codeBaseRootPath, "*.csproj|*.vbproj"); List<Project> sequencedProjects = bs.SequenceProjects(); StringBuilder dosScriptText = new StringBuilder(); dosScriptText.AppendLine("@ECHO OFF"); dosScriptText.AppendLine("SET \"MSBuildExe=C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe\""); dosScriptText.AppendLine("SET \"ConfigMode=Debug\""); dosScriptText.AppendLine("\nREM Clean up all projects."); foreach (Project p in sequencedProjects) { dosScriptText.AppendLine(string.Format("CALL %MSBuildExe% \"{0}\" /t:Clean", p.ProjectFileName)); dosScriptText.AppendLine("IF NOT %ERRORLEVEL%==0 GOTO :ExitOnError"); } dosScriptText.AppendLine("\nREM Build all projects."); foreach (Project p in sequencedProjects) { dosScriptText.AppendLine(string.Format("CALL %MSBuildExe% \"{0}\" /t:Rebuild /p:Configuration=%ConfigMode%", p.ProjectFileName)); dosScriptText.AppendLine("IF NOT %ERRORLEVEL%==0 GOTO :ExitOnError"); } dosScriptText.AppendLine("\nECHO \"Successfully completed.\""); dosScriptText.AppendLine("GOTO :ExitNoError"); dosScriptText.AppendLine("\n:ExitOnError"); dosScriptText.AppendLine("ECHO \"Errors occurred.\""); dosScriptText.AppendLine("\n:ExitNoError"); if (rbCreateFile.IsChecked == true) { string buildScriptFileName = System.IO.Path.Combine(codeBaseRootPath, "DebugBuildScript.bat"); using (System.IO.StreamWriter f = new System.IO.StreamWriter(buildScriptFileName)) { f.Write(dosScriptText.ToString()); } MessageBox.Show("The build sequencing has completed and a script has been created in the code base's root folder.", "Build Sequencing Completed", MessageBoxButton.OK, MessageBoxImage.Information); } else { Clipboard.Clear(); Clipboard.SetText(dosScriptText.ToString()); MessageBox.Show("The build sequencing has completed and a script has been copied to your clipboard.", "Build Sequencing Completed", MessageBoxButton.OK, MessageBoxImage.Information); } } finally { this.Cursor = Cursors.Arrow; } }
private void Window_Loaded(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(_rootFolder) || !Directory.Exists(_rootFolder)) { this.Close(); return; } BuildSequencer bs = new BuildSequencer(); bs.Load(_rootFolder, "*.csproj|*.vbproj"); List<Project> projList = bs.SequenceProjects(); int i = 0; lvProjects.Items.Clear(); foreach (Project p in projList) { ListViewItem lvi = new ListViewItem(); lvi.Content = p.ProjectFileName; lvi.Tag = p; lvProjects.Items.Add(lvi); if (i == 0) { lvi.IsSelected = true; } i++; } }