/// <summary> /// Get default project in the type of <see cref="IVsProjectAdapter"/>, to keep PowerShell scripts backward-compatbility. /// </summary> /// <returns></returns> protected async Task <IVsProjectAdapter> GetDefaultProjectAsync() { var defaultNuGetProject = await VsSolutionManager.GetDefaultNuGetProjectAsync(); // Solution may be open without a project in it. Then defaultNuGetProject is null. if (defaultNuGetProject != null) { return(await VsSolutionManager.GetVsProjectAdapterAsync(defaultNuGetProject)); } return(null); }
/// <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 <IVsProjectAdapter> > GetProjectsByNameAsync(string[] projectNames) { var result = new List <IVsProjectAdapter>(); var allValidProjectNames = await GetAllValidProjectNamesAsync(); 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 = await VsSolutionManager.GetNuGetProjectAsync(match); if (matchedProject != null) { var projectAdapter = await VsSolutionManager.GetVsProjectAdapterAsync(matchedProject); result.Add(projectAdapter); } } } return(result); }