public static void Execute(AddProjectToSolutionInfo info, string templateDirectory, string strongNamePath = null, NuGetSettings nuGetSettings = null) { Logger.AddDetail($"Starting to process solution '{info.SolutionPath}' using templates from '{templateDirectory}'"); var adder = new SolutionUpdater(info.SolutionPath, templateDirectory, strongNamePath, nuGetSettings); adder.Projects = adder.GetProjectInfos(info); adder.CreateProjects(string.Empty); IEnumerable <string> solution = File.ReadAllLines(adder.SolutionPath); solution = SolutionFileEditor.AddMissingProjects(solution, adder.Projects.Values); File.WriteAllLines(adder.SolutionPath, solution); adder.ExecuteNuGetRestoreForSolution(); }
private static void UpdateSolution(InitializeSolutionInfo info, SolutionInitializer logic) { Logger.Show("Updating Solution"); IEnumerable <string> solution = File.ReadAllLines(logic.SolutionPath); solution = SolutionFileEditor.AddMissingProjects(solution, logic.Projects.Values); if (info.IncludeCodeGenerationFiles) { var parser = new SolutionFileParser(solution); var codeGenPath = Path.Combine(logic.TemplateDirectory, "CodeGeneration"); var outputPath = Path.Combine(Path.GetDirectoryName(info.SolutionPath) ?? "", "CodeGeneration"); Directory.CreateDirectory(outputPath); var files = new List <string>(); foreach (var file in Directory.GetFiles(codeGenPath)) { Logger.AddDetail($"Adding {file} to the solution..."); var name = "CodeGeneration\\" + Path.GetFileName(file); var outputFile = Path.Combine(outputPath, Path.GetFileName(file)); files.Add($"\t\t{name} = {name}"); if (File.Exists(outputFile)) { Logger.AddDetail($"File '{outputFile}' already existing. Skipping Adding"); continue; } File.Copy(file, outputFile); } parser.Projects.Add($@"Project(""{{2150E333-8FDC-42A3-9474-1A3956D46DE8}}"") = ""Code Generation"", ""Code Generation"", ""{{{Guid.NewGuid()}}}"" ProjectSection(SolutionItems) = preProject {string.Join(Environment.NewLine, files)} EndProjectSection EndProject"); File.WriteAllLines(logic.SolutionPath, parser.GetSolution()); } else { File.WriteAllLines(logic.SolutionPath, solution); } }