示例#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 IEnumerable <EnvDTE.Project> GetProjectsByName(string[] projectNames)
        {
            var allValidProjectNames = GetAllValidProjectNames().ToList();

            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 _solutionManager.GetProject(s);

                int count = 0;
                foreach (var project in matches)
                {
                    count++;
                    yield return(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 ((count == 0) && !WildcardPattern.ContainsWildcardCharacters(projectName))
                {
                    ErrorHandler.WriteProjectNotFoundError(projectName, terminating: false);
                }
            }
        }
        public Project GetProject(IProjectManager projectManager)
        {
            // We only support project systems that implement IVsProjectSystem
            var vsProjectSystem = projectManager.Project as IVsProjectSystem;
            if (vsProjectSystem == null)
            {
                return null;
            }

            // Find the project by it's unique name
            return _solutionManager.GetProject(vsProjectSystem.UniqueName);
        }
        public async void OpenSolutionClick()
        {
            //TODO get parent solutions view

            var solution = string.Empty;

            if (SelectedSolutionItem is ProjectViewModel pvm)
            {
                // solution = pvm.Project.Solution;
            }
            else if (SelectedSolutionItem is ProjectDirectRefViewModel pdr)
            {
                var pd = await _solutionManager.GetProject(pdr.ProjectReference.FilePath);

                if (pd != ProjectDetails.Empty)
                {
                    // solution = pd.Solution;
                }
            }
            else if (SelectedSolutionItem is ProjectRefViewModel prv)
            {
                var pd = await _solutionManager.GetProject(prv.ProjectReference.FilePath);

                if (pd != ProjectDetails.Empty)
                {
                    // solution = pd.Solution;
                }
            }
            else if (SelectedSolutionItem is ReferencedViewModel rvm)
            {
                //solution = rvm.Solution;
            }

            if (solution != string.Empty)
            {
                Process.Start(Environment.GetEnvironmentVariable("WINDIR") + @"\explorer.exe", solution);
            }
        }
示例#4
0
 private void OnPackageReferenceAdded(IVsPackageMetadata metadata)
 {
     if (IsCurrentSolutionEnabledForRestore)
     {
         var packageMetadata = (VsPackageMetadata)metadata;
         var fileSystem      = packageMetadata.FileSystem as IVsProjectSystem;
         if (fileSystem != null)
         {
             var project = _solutionManager.GetProject(fileSystem.UniqueName);
             if (project != null)
             {
                 // in this case, we know that this project has at least one nuget package,
                 // so enable package restore straight away
                 EnablePackageRestore(project);
             }
         }
     }
 }
示例#5
0
        public void ShouldBeAbleToSpecifyArbitraryProjectName()
        {
            // Arrange
            var vbProject       = _solutionManager.GetProject("myVbProject");
            var mockConfigStore = new Mock <IScaffoldingConfigStore>();

            mockConfigStore.Setup(x => x.GetProjectDefaultScaffolders(vbProject)).Returns(SampleConfig.AsQueryable());

            // Act
            var cmdlet = new GetDefaultScaffolderCmdlet(_solutionManager, null, mockConfigStore.Object)
            {
                Project = vbProject.Name
            };
            var results = cmdlet.GetResults <DefaultScaffolderConfigEntry>();

            // Assert
            CollectionAssert.AreEquivalent(SampleConfig, results.ToList());
        }
示例#6
0
        public void ShouldBeAbleToSpecifyArbitraryProjectName()
        {
            // Arrange
            var vbProject             = _solutionManager.GetProject("myVbProject");
            var mockScaffolderLocator = new Mock <IScaffolderLocator>();
            var expectedResult        = new List <ScaffolderInfo> {
                new ScaffolderInfo("name1", "packagename1", "location1", null, null),
                new ScaffolderInfo("name2", "packagename2", "location2", null, null),
            };

            mockScaffolderLocator.Setup(x => x.GetScaffolders(vbProject, "someScaffolder", true)).Returns(expectedResult);

            // Act
            var results = new GetScaffolderCmdlet(_solutionManager, null, mockScaffolderLocator.Object)
            {
                Name    = "someScaffolder",
                Project = vbProject.Name
            }.GetResults <ScaffolderInfo>();

            // Assert
            CollectionAssert.AreEqual(expectedResult, results.ToList());
        }
        public void ShouldBeAbleToWriteConfigToArbitraryProject()
        {
            // Arrange
            var mockConfigStore       = new Mock <IScaffoldingConfigStore>();
            var mockScaffolderLocator = new Mock <IScaffolderLocator>();
            var vbProject             = _solutionManager.GetProject("myVbProject");

            mockScaffolderLocator.Setup(x => x.GetScaffolders(vbProject, "someScaffolder", false)).Returns(new[] {
                new ScaffolderInfo("foundScaffolderName", null, null, null, null)
            });

            // Act
            var results = new SetDefaultScaffolderCmdlet(_solutionManager, null, mockConfigStore.Object, mockScaffolderLocator.Object)
            {
                Name       = "someDefault",
                Scaffolder = "someScaffolder",
                Project    = vbProject.Name
            }.GetResults <DefaultScaffolderConfigEntry>();

            // Assert
            Assert.AreEqual(0, results.Count());
            mockConfigStore.Verify(x => x.SetProjectDefaultScaffolder(vbProject, "someDefault", "foundScaffolderName", false));
        }
示例#8
0
        private Project FindProjectFromFileSystem(IFileSystem fileSystem)
        {
            var projectSystem = fileSystem as IVsProjectSystem;

            return(_solutionManager.GetProject(projectSystem.UniqueName));
        }