private static void GenSln(List <PrjInfo> thisLevel, int level) { var prjs = thisLevel.Where(item => !string.IsNullOrEmpty(item.PrjFilePath)).ToList(); if (prjs.Count == 0) { return; } var generator = new SolutionGenerator(new ConsoleLogger()); var slnOpt = new SolutionOptions(); slnOpt.SolutionFolderPath = SlnPath + "buildSln" + level.ToString().PadLeft(3, '0') + ".sln"; slnOpt.SolutionFileVersion = SolutionFileVersion.VisualStudio2012; slnOpt.ProjectRootFolderPath = prjs.FirstOrDefault().PrjFilePath; generator.GenerateSolution(slnOpt.SolutionFolderPath, slnOpt); prjs.RemoveAt(0); foreach (var prj in prjs) { slnOpt.UpdateMode = SolutionUpdateMode.Add; slnOpt.ProjectRootFolderPath = prj.PrjFilePath; generator.GenerateSolution(slnOpt.SolutionFolderPath, slnOpt); } }
public void CanGeneratorSolution(string configurationGroup) { DocumentReader sol = generator.Reader; generator.GenerateSolution(configurationGroup); Assert.Single(sol.Templates); Assert.Equal(2, sol.Modules.Count); Assert.NotNull(sol.Solution); Assert.True(sol.Solution.CanIncludeProject("MyModule")); Assert.True(sol.Solution.CanIncludeProject("MyOtherModule")); Assert.True(sol.Solution.CanIncludeProject("MyModule.Tests")); Assert.True(sol.Solution.CanIncludeProject("MyOtherModule.Tests")); Assert.True(sol.Modules.ContainsKey("MyModule")); Assert.True(sol.Modules.ContainsKey("MyOtherModule")); Assert.True(sol.Templates.ContainsKey("MyTemplate")); Module module = sol.Modules["MyModule"]; ICollection <Project> moduleProjects = GetIncludedProjects(configurationGroup, module); Assert.Equal("MyModule", module.Name); Assert.Equal(configurationGroup == "everything" ? 2 : 1, moduleProjects.Count); Project mainProject = moduleProjects.ElementAt(0); Assert.Equal("MyModule", mainProject.Name); Assert.Equal("8CA3145D-B47F-4355-808A-2C08F48EB061", mainProject.Guid.ToString().ToUpper()); if (configurationGroup == "everything") { Project testsProject = moduleProjects.ElementAt(1); Assert.Equal("MyModule.Tests", testsProject.Name); Assert.Equal("3B8C3242-A267-4E63-9AE2-7099ACB9F730", testsProject.Guid.ToString().ToUpper()); } Assert.Equal(1, module.Configurations.Keys.Count(cfg => cfg.Name == "Debug" && cfg.GroupName == configurationGroup)); Assert.Equal(1, module.Configurations.Keys.Count(cfg => cfg.Name == "Release" && cfg.GroupName == configurationGroup)); Configuration debug = module.Configurations.Keys.First(cfg => cfg.Name == "Debug"); Configuration release = module.Configurations.Keys.First(cfg => cfg.Name == "Release"); Project firstDebugProject = module.Configurations[debug].Projects.Values.First(); Project firstReleaseProject = module.Configurations[release].Projects.Values.First(); var debugDefines = firstDebugProject.Settings.GetProperty <HashSet <string> >(Settings.PROP_DEFINE_CONSTANTS); var releaseDefines = firstReleaseProject.Settings.GetProperty <HashSet <string> >(Settings.PROP_DEFINE_CONSTANTS); Assert.Contains("DEBUG", debugDefines); Assert.Contains("RELEASE", releaseDefines); Assert.DoesNotContain("DEBUG", releaseDefines); if (configurationGroup == "everything") { Assert.Contains("TEST", debugDefines); Assert.DoesNotContain("TEST", releaseDefines); } Assert.Contains("Sprache.dll", firstDebugProject.LibRefs.First()); Assert.Contains("Sprache.dll", firstReleaseProject.LibRefs.First()); }
public static void GenSln(List <PrjInfo> thisLevel, int level, string slnDir = null) { if (IsNullOrEmpty(slnDir)) { slnDir = BomBuildOption.SlnPath; } if (!Directory.Exists(slnDir)) { Directory.CreateDirectory(slnDir); } var prjs = thisLevel.Where(item => !IsNullOrEmpty(item.PrjFilePath)).ToList(); if (prjs.Count == 0) { return; } var generator = new SolutionGenerator(new ConsoleLogger()); var firstPrj = prjs.First(); var slnFilePath = Path.Combine(slnDir, $"{firstPrj.BuildStage}BuildSln{level.ToString().PadLeft(3, '0')}"); //创建一个空解决方案,否则第一个项目的相对路径会出错 using (var fs = File.Create(slnFilePath)) { } var slnOpt = new SolutionOptions { SolutionFolderPath = slnFilePath, SolutionFileVersion = SolutionFileVersion.VisualStudio2012, ProjectRootFolderPath = firstPrj.PrjFilePath }; generator.GenerateSolution(slnOpt.SolutionFolderPath, slnOpt); prjs.RemoveAt(0); foreach (var prj in prjs) { slnOpt.UpdateMode = SolutionUpdateMode.Add; slnOpt.ProjectRootFolderPath = prj.PrjFilePath; generator.GenerateSolution(slnOpt.SolutionFolderPath, slnOpt); } //添加build所需的Section AdjustBuildSln(slnOpt.SolutionFolderPath, prjs); }
private void buttonPreview_Click(object sender, EventArgs e) { try { string message; SolutionOptions options = CreateOptionsFromControls(); SolutionGenerator generator = new SolutionGenerator(new StatusLogger(this.labelStatus)); var solution = generator.GenerateSolution(this.textSolutionFile.Text, options, true); this.labelStatus.Text = string.Empty; if (generator.NumberOfProjectsFound == 0) { message = string.Format("No project files found in the specified location\r\nSolution file is not generated"); MessageBox.Show(message, "Execution Summary", MessageBoxButtons.OK); } else { var previewForm = new PreviewForm(); previewForm.Solution = solution; previewForm.SolutionFile = this.textSolutionFile.Text; previewForm.ShowDialog(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonExecute_Click(object sender, EventArgs e) { try { string message; if (File.Exists(this.textSolutionFile.Text)) { var fileAttributes = File.GetAttributes(this.textSolutionFile.Text); if ((fileAttributes & FileAttributes.ReadOnly) != 0) { message = "The solution file is read only\r\nDo you want to overwrite it?"; if (MessageBox.Show(message, "Confirm Overwrite", MessageBoxButtons.YesNo) == DialogResult.Yes) { File.SetAttributes(this.textSolutionFile.Text, fileAttributes ^ FileAttributes.ReadOnly); } else { return; } } } SolutionOptions options = CreateOptionsFromControls(); SolutionGenerator generator = new SolutionGenerator(new StatusLogger(this.labelStatus)); generator.GenerateSolution(this.textSolutionFile.Text, options); this.labelStatus.Text = string.Empty; if (generator.NumberOfProjectsFound > 0) { message = string.Format("Solution file is generated\r\n\r\n{0} projects found\r\n{1} projects skipped\r\n{2} projects added\r\n{3} projects removed", generator.NumberOfProjectsFound, generator.NumberOfProjectsSkipped, generator.NumberOfProjectsAdded, generator.NumberOfProjectsRemoved); } else { message = string.Format("No project files found in the specified location\r\nSolution file is not generated"); } if (this.checkSaveSettings.Checked) { SaveSettings(options, Path.ChangeExtension(this.textSolutionFile.Text, SolutionOptions.FileExtension)); } MessageBox.Show(message, "Execution Summary", MessageBoxButtons.OK); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private ErrorCode GenerateSolution() { if (SkipGenerateCommand) { return(ErrorCode.Success); } Log.Debug("Config = " + SolutionConfigFile.FullName); Log.Debug("Define Symbols ="); if (defineSymbols.Count > 0) { Log.IndentedCollection(defineSymbols, Log.Debug); } Log.Debug("Variables ="); if (Variables.Count > 0) { Log.IndentedCollection(Variables, kvp => $"{kvp.Key} => {kvp.Value}", Log.Debug); } try { solution = GetGenerator(); solution.GenerateSolution( MasterConfiguration, defineSymbols.ToArray(), PropertyOverrides.ToArray(), string.IsNullOrEmpty(BuildConfiguration) ? null : new[] { BuildConfiguration }); // If MasterConfiguration was null or empty, the generator will select a default. MasterConfiguration = solution.MasterConfiguration; } catch (Exception ex) { Log.Error("{0}", ex.ToString()); return(ErrorCode.GeneratorException); } File.WriteAllText(Path.Combine(solution.Solution.OutputDir, solution.Solution.Name + ".sln.config"), "MasterConfiguration=" + MasterConfiguration); return(ErrorCode.Success); }
private static void GenerateSolutionFile(CommandLineOptions options) { if (!Directory.Exists(options.ProjectRootFolderPath)) { throw new SolutionFileGenerationException("Invalid directory: " + options.ProjectRootFolderPath); } else if (File.Exists(options.SolutionFile) && ((File.GetAttributes(options.SolutionFile) & FileAttributes.ReadOnly) != 0) && !options.OverwriteReadOnlyFile) { throw new SolutionFileGenerationException("Solution file is read-only. Use /r option to overwrite read-only solution file."); } else { if (File.Exists(options.SolutionFile)) { var fileAttributes = File.GetAttributes(options.SolutionFile); if ((fileAttributes & FileAttributes.ReadOnly) != 0 && options.OverwriteReadOnlyFile) { File.SetAttributes(options.SolutionFile, fileAttributes ^ FileAttributes.ReadOnly); } } SolutionGenerator generator = new SolutionGenerator(new ConsoleLogger()); generator.GenerateSolution(options.SolutionFile, options); string message; if (generator.NumberOfProjectsFound > 0) { message = string.Format("Solution file is generated\r\n{0} projects found\r\n{1} projects skipped\r\n{2} projects added\r\n{3} projects removed", generator.NumberOfProjectsFound, generator.NumberOfProjectsSkipped, generator.NumberOfProjectsAdded, generator.NumberOfProjectsRemoved); } else { message = string.Format("No project files found in the specified location\r\nSolution file is not generated"); } Console.WriteLine(); Console.WriteLine(message); } }