/// <summary> /// Get default project in the type of <see cref="IVsProjectAdapter"/>, to keep PowerShell scripts backward-compatbility. /// </summary> /// <returns></returns> protected IVsProjectAdapter GetDefaultProject() { var defaultNuGetProject = VsSolutionManager.DefaultNuGetProject; // Solution may be open without a project in it. Then defaultNuGetProject is null. if (defaultNuGetProject != null) { return(VsSolutionManager.GetVsProjectAdapter(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 IEnumerable <IVsProjectAdapter> GetProjectsByName(string[] projectNames) { var allValidProjectNames = GetAllValidProjectNames().ToList(); 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)) .Select(s => VsSolutionManager.GetNuGetProject(s)) .Where(p => p != null) .ToList(); foreach (var project in matches) { yield return(VsSolutionManager.GetVsProjectAdapter(project)); } // 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.Count == 0) && !WildcardPattern.ContainsWildcardCharacters(projectName)) { ErrorHandler.WriteProjectNotFoundError(projectName, terminating: false); } } }