public override int Run(string fileOrDirectory) { SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(fileOrDirectory); if (RemainingArguments.Count == 0) { throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToRemove); } var relativeProjectPaths = RemainingArguments.Select((p) => PathUtility.GetRelativePath( PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory), Path.GetFullPath(p))).ToList(); bool slnChanged = false; foreach (var path in relativeProjectPaths) { slnChanged |= RemoveProject(slnFile, path); } RemoveEmptyConfigurationSections(slnFile); RemoveEmptySolutionFolders(slnFile); if (slnChanged) { slnFile.Write(); } return(0); }
public override int Execute() { SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory); if (_appliedCommand.Arguments.Count == 0) { throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd); } PathUtility.EnsureAllPathsExist(_appliedCommand.Arguments, CommonLocalizableStrings.CouldNotFindProjectOrDirectory, true); var fullProjectPaths = _appliedCommand.Arguments.Select(p => { var fullPath = Path.GetFullPath(p); return(Directory.Exists(fullPath) ? MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName : fullPath); }).ToList(); var preAddProjectCount = slnFile.Projects.Count; foreach (var fullProjectPath in fullProjectPaths) { slnFile.AddProject(fullProjectPath); } if (slnFile.Projects.Count > preAddProjectCount) { slnFile.Write(); } return(0); }
public override int Run(string fileOrDirectory) { SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(fileOrDirectory); if (RemainingArguments.Count == 0) { throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd); } PathUtility.EnsureAllPathsExist(RemainingArguments, CommonLocalizableStrings.ProjectDoesNotExist); var fullProjectPaths = RemainingArguments.Select((p) => Path.GetFullPath(p)).ToList(); int preAddProjectCount = slnFile.Projects.Count; foreach (var fullProjectPath in fullProjectPaths) { slnFile.AddProject(fullProjectPath); } if (slnFile.Projects.Count > preAddProjectCount) { slnFile.Write(); } return(0); }
public override int Execute() { SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory); var baseDirectory = PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory); var relativeProjectPaths = _arguments.Select(p => { var fullPath = Path.GetFullPath(p); return(Path.GetRelativePath( baseDirectory, Directory.Exists(fullPath) ? MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName : fullPath )); }); bool slnChanged = false; foreach (var path in relativeProjectPaths) { slnChanged |= slnFile.RemoveProject(path); } slnFile.RemoveEmptyConfigurationSections(); slnFile.RemoveEmptySolutionFolders(); if (slnChanged) { slnFile.Write(); } return(0); }
public override int Execute() { SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory); var relativeProjectPaths = _appliedCommand.Arguments.Select(p => PathUtility.GetRelativePath( PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory), Path.GetFullPath(p))) .ToList(); bool slnChanged = false; foreach (var path in relativeProjectPaths) { slnChanged |= slnFile.RemoveProject(path); } slnFile.RemoveEmptyConfigurationSections(); slnFile.RemoveEmptySolutionFolders(); if (slnChanged) { slnFile.Write(); } return(0); }
public ListProjectsInSolution(string fileOrDirectory) { SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(fileOrDirectory); foreach (var slnProject in slnFile.Projects) { _items.Add(slnProject.FilePath); } }
public override int Run(string fileOrDirectory) { SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(fileOrDirectory); if (slnFile.Projects.Count == 0) { Reporter.Output.WriteLine(CommonLocalizableStrings.NoProjectsFound); } else { Reporter.Output.WriteLine($"{CommonLocalizableStrings.ProjectReferenceOneOrMore}"); Reporter.Output.WriteLine(new string('-', CommonLocalizableStrings.ProjectReferenceOneOrMore.Length)); foreach (var slnProject in slnFile.Projects) { Reporter.Output.WriteLine(slnProject.FilePath); } } return(0); }
public override int Execute() { SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory); if (slnFile.Projects.Count == 0) { Reporter.Output.WriteLine(CommonLocalizableStrings.NoProjectsFound); } else { Reporter.Output.WriteLine($"{LocalizableStrings.ProjectsHeader}"); Reporter.Output.WriteLine(new string('-', LocalizableStrings.ProjectsHeader.Length)); foreach (var slnProject in slnFile.Projects.Where(p => p.TypeGuid != ProjectTypeGuids.SolutionFolderGuid)) { Reporter.Output.WriteLine(slnProject.FilePath); } } return(0); }
public override int Execute() { SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory); var arguments = (_parseResult.ValueForArgument <IEnumerable <string> >(SlnAddParser.ProjectPathArgument) ?? Array.Empty <string>()).ToList().AsReadOnly(); if (arguments.Count == 0) { throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd); } PathUtility.EnsureAllPathsExist(arguments, CommonLocalizableStrings.CouldNotFindProjectOrDirectory, true); var fullProjectPaths = arguments.Select(p => { var fullPath = Path.GetFullPath(p); return(Directory.Exists(fullPath) ? MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName : fullPath); }).ToList(); var preAddProjectCount = slnFile.Projects.Count; foreach (var fullProjectPath in fullProjectPaths) { // Identify the intended solution folders var solutionFolders = DetermineSolutionFolder(slnFile, fullProjectPath); slnFile.AddProject(fullProjectPath, solutionFolders); } if (slnFile.Projects.Count > preAddProjectCount) { slnFile.Write(); } return(0); }
internal static CommandLineApplication CreateApplication(CommandLineApplication parentApp) { CommandLineApplication app = parentApp.Command("project", throwOnUnexpectedArg: false); app.FullName = LocalizableStrings.AppFullName; app.Description = LocalizableStrings.AppDescription; app.HandleRemainingArguments = true; app.ArgumentSeparatorHelpText = LocalizableStrings.AppHelpText; app.HelpOption("-h|--help"); app.OnExecute(() => { try { if (!parentApp.Arguments.Any()) { throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, Constants.ProjectOrSolutionArgumentName); } var projectOrDirectory = parentApp.Arguments.First().Value; if (string.IsNullOrEmpty(projectOrDirectory)) { projectOrDirectory = PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()); } SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(projectOrDirectory); if (app.RemainingArguments.Count == 0) { throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd); } List <string> projectPaths = app.RemainingArguments; PathUtility.EnsureAllPathsExist(projectPaths, CommonLocalizableStrings.ProjectDoesNotExist); var relativeProjectPaths = projectPaths.Select((p) => PathUtility.GetRelativePath( PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory), Path.GetFullPath(p))).ToList(); int preAddProjectCount = slnFile.Projects.Count; foreach (var project in relativeProjectPaths) { AddProject(slnFile, project); } if (slnFile.Projects.Count > preAddProjectCount) { slnFile.Write(); } return(0); } catch (GracefulException e) { Reporter.Error.WriteLine(e.Message.Red()); app.ShowHelp(); return(1); } }); return(app); }
/// <summary> /// Generate the template defined in the template file set in <see cref="Settings"/>. /// </summary> public void Generate(GeneratorArguments arguments) { _logger = new Logger { LogLevel = Settings.LogLevel, LogWriter = Settings.LogWriter ?? Console.Out, SupressErrors = Settings.SupressErrors }; if (_template == null) { _logger.Log(LogLevel.Error, "A template needs to be loaded before calling generate."); return; } if (File.Exists(arguments.DestinationFolder) || (Directory.Exists(arguments.DestinationFolder) && Directory.EnumerateFileSystemEntries(arguments.DestinationFolder).Any() && !Settings.Overwrite)) { _logger.Log(LogLevel.Error, $"The destination directory '{arguments.DestinationFolder}' already exists and is not empty. Set the Overwrite flag to write anyway."); return; } var dst = Path.GetFullPath(arguments.DestinationFolder); if (_template.HasFatalError) { return; } var variables = _template.Variables.With(arguments.Variables); variables.Set(Template.SourceFileExtensionVariable, arguments.SourceLanguage.GetFileExtension()); Directory.CreateDirectory(dst); var projectPaths = new List <string>(); foreach (var pe in _template.ProjectEntries) { var adst = RenderFileEntry(pe, variables, dst); _logger.Log(LogLevel.Info, $"Rendered project '{pe.AbsoluteSrc}' to '{adst}'."); projectPaths.Add(adst); foreach (var fe in pe.FileEntries) { adst = RenderFileEntry(fe, variables, dst); _logger.Log(LogLevel.Info, $"Rendered file '{fe.AbsoluteSrc}' to '{adst}'."); } } if (arguments.Solution != null) { var slnPath = Path.GetFullPath(arguments.Solution); SlnFile sln; if (File.Exists(arguments.Solution)) { sln = SlnFileFactory.CreateFromFileOrDirectory(arguments.Solution); } else { sln = new SlnFile { FullPath = slnPath }; sln.FormatVersion = "12.00"; sln.MinimumVisualStudioVersion = "10.0.40219.1"; _logger.Log(LogLevel.Info, $"Created solution '{Path.GetFileName(slnPath)}'."); } foreach (var projectPath in projectPaths) { sln.AddProject(projectPath); _logger.Log(LogLevel.Info, $"Added project '{Path.GetFileName(projectPath)}' to solution '{Path.GetFileName(slnPath)}'."); } sln.Write(); } }