protected override void ProcessRecordCore() { Preprocess(); if (All.IsPresent) { var projects = SolutionManager.GetAllProjectsAsync().Result; WriteObject(projects, enumerateCollection: true); } else { // No name specified; return default project (if not null) if (Name == null) { var defaultProject = GetDefaultProjectAsync().Result; if (defaultProject != null) { WriteObject(defaultProject); } } else { // get all projects matching name(s) - handles wildcards var projects = GetProjectsByNameAsync(Name).Result; WriteObject(projects, enumerateCollection: true); } } }
protected override void Preprocess() { base.Preprocess(); if (string.IsNullOrEmpty(ProjectName)) { ProjectName = DTEProject.Name; } Task.Run(async() => { // Get the projects in the solution that's not the current default or specified project to sync the package identity to. var projects = await SolutionManager.GetAllProjectsAsync(); DTEProjects = projects .Where(p => !StringComparer.OrdinalIgnoreCase.Equals(p.Name, ProjectName)) .Select(project => (Project)project) .ToList(); }).Wait(); }
/// <summary> /// Return all projects in the solution matching the provided names. Wildcards are supported. /// This method will automatically generate error records for non-wildcarded project names that /// are not found. /// </summary> /// <param name="projectNames">An array of project names that may or may not include wildcards.</param> /// <returns>Projects matching the project name(s) provided.</returns> protected async Task <IEnumerable <EnvDTE.Project> > GetProjectsByNameAsync(string[] projectNames) { var result = new List <EnvDTE.Project> (); var allProjects = (await SolutionManager.GetAllProjectsAsync()).ToList(); var allValidProjectNames = await GetAllValidProjectNamesAsync(allProjects); foreach (var projectName in projectNames) { // if ctrl+c hit, leave immediately if (Stopping) { break; } // Treat every name as a wildcard; results in simpler code var pattern = new WildcardPattern(projectName, WildcardOptions.IgnoreCase); var matches = allValidProjectNames .Where(s => pattern.IsMatch(s)) .ToArray(); // We only emit non-terminating error record if a non-wildcarded name was not found. // This is consistent with built-in cmdlets that support wildcarded search. // A search with a wildcard that returns nothing should not be considered an error. if ((matches.Length == 0) && !WildcardPattern.ContainsWildcardCharacters(projectName)) { ErrorHandler.WriteProjectNotFoundError(projectName, terminating: false); } foreach (var match in matches) { var matchedProject = GetProject(allProjects, match); if (matchedProject != null) { if (!result.Contains(matchedProject)) { result.Add(matchedProject); } } } } return(result); }
protected override void Preprocess() { base.Preprocess(); ParseUserInputForVersion(); if (!projectSpecified) { Task.Run(async() => { var projects = await SolutionManager.GetAllProjectsAsync(); DTEProjects = projects.Select(project => (Project)project).ToList(); }).Wait(); } else { DTEProjects = new List <Project> { DTEProject }; } }
void Preprocess() { UseRemoteSourceOnly = ListAvailable.IsPresent || (!String.IsNullOrEmpty(Source) && !Updates.IsPresent); UseRemoteSource = ListAvailable.IsPresent || Updates.IsPresent || !String.IsNullOrEmpty(Source); CollapseVersions = !AllVersions.IsPresent; UpdateActiveSourceRepository(Source); Task.Run(async() => { // When ProjectName is not specified, get all of the projects in the solution if (string.IsNullOrEmpty(ProjectName)) { var projects = await SolutionManager.GetAllProjectsAsync(); DTEProjects = projects.Select(project => (Project)project).ToList(); } else { await GetDTEProjectAsync(ProjectName); DTEProjects = new List <Project> { DTEProject }; } }).Wait(); }