Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the default NuGet Project
        /// </summary>
        /// <param name="projectName"></param>
        protected async Task GetNuGetProjectAsync(string projectName = null)
        {
            if (string.IsNullOrEmpty(projectName))
            {
                Project = await VsSolutionManager.GetDefaultNuGetProjectAsync();

                if ((await VsSolutionManager.IsSolutionAvailableAsync()) &&
                    Project == null)
                {
                    ErrorHandler.WriteProjectNotFoundError("Default", terminating: true);
                }
            }
            else
            {
                Project = await VsSolutionManager.GetNuGetProjectAsync(projectName);

                if ((await VsSolutionManager.IsSolutionAvailableAsync()) &&
                    Project == null)
                {
                    ErrorHandler.WriteProjectNotFoundError(projectName, terminating: true);
                }
            }
        }