protected IEnumerable <NuGetProject> GetNuGetProjectsByName(string[] projectNames)
        {
            List <NuGetProject> nuGetProjects = new List <NuGetProject>();

            foreach (Project project in GetProjectsByName(projectNames))
            {
                NuGetProject nuGetProject = VsSolutionManager.GetNuGetProject(project.Name);
                if (nuGetProject != null)
                {
                    nuGetProjects.Add(nuGetProject);
                }
            }
            return(nuGetProjects);
        }
        /// <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 <Project> GetProjectsByName(string[] projectNames)
        {
            var allValidProjectNames = GetAllValidProjectNames().ToList();
            var allDteProjects       = EnvDTESolutionUtility.GetAllEnvDTEProjects(DTE);

            foreach (string 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 = from s in allValidProjectNames
                              where pattern.IsMatch(s)
                              select VsSolutionManager.GetNuGetProject(s);

                int count = 0;
                foreach (var project in matches)
                {
                    if (project != null)
                    {
                        count++;
                        string  name       = project.GetMetadata <string>(NuGetProjectMetadataKeys.UniqueName);
                        Project dteProject = allDteProjects
                                             .Where(p => StringComparer.OrdinalIgnoreCase.Equals(EnvDTEProjectUtility.GetCustomUniqueName(p), name))
                                             .FirstOrDefault();
                        yield return(dteProject);
                    }
                }

                // 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 ((count == 0) &&
                    !WildcardPattern.ContainsWildcardCharacters(projectName))
                {
                    ErrorHandler.WriteProjectNotFoundError(projectName, terminating: false);
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Get the default NuGet Project
 /// </summary>
 /// <param name="projectName"></param>
 protected void GetNuGetProject(string projectName = null)
 {
     if (string.IsNullOrEmpty(projectName))
     {
         Project = VsSolutionManager.DefaultNuGetProject;
         if (VsSolutionManager.IsSolutionAvailable &&
             Project == null)
         {
             ErrorHandler.WriteProjectNotFoundError("Default", terminating: true);
         }
     }
     else
     {
         Project = VsSolutionManager.GetNuGetProject(projectName);
         if (VsSolutionManager.IsSolutionAvailable &&
             Project == null)
         {
             ErrorHandler.WriteProjectNotFoundError(projectName, terminating: true);
         }
     }
 }
Beispiel #4
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 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);
                }
            }
        }