Esempio n. 1
0
        private async Task SetDefaultProjectNameAsync()
        {
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IEnumerable <object> startupProjects;

            try
            {
                // when a new solution opens, we set its startup project as the default project in NuGet Console
                var dte = await _dte.GetValueAsync();

                var solutionBuild = dte.Solution.SolutionBuild as SolutionBuild2;
                startupProjects = solutionBuild?.StartupProjects as IEnumerable <object>;
            }
            catch (COMException)
            {
                // get_StartupProjects misbehaves for certain project types, so ignore this failure
                return;
            }

            var startupProjectName = startupProjects?.Cast <string>().FirstOrDefault();

            if (!string.IsNullOrEmpty(startupProjectName))
            {
                if (_projectSystemCache.TryGetProjectNames(startupProjectName, out var projectName))
                {
                    DefaultNuGetProjectName = _projectSystemCache.IsAmbiguous(projectName.ShortName) ?
                                              projectName.CustomUniqueName :
                                              projectName.ShortName;
                }
            }
        }
Esempio n. 2
0
        private void SetDefaultProjectName()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IEnumerable <object> startupProjects;

            try
            {
                // when a new solution opens, we set its startup project as the default project in NuGet Console
                var dte           = _serviceProvider.GetDTE();
                var solutionBuild = dte.Solution.SolutionBuild as SolutionBuild2;
                startupProjects = solutionBuild?.StartupProjects as IEnumerable <object>;
            }
            catch (COMException)
            {
                // get_StartupProjects misbehaves for certain project types, so ignore this failure
                return;
            }

            var startupProjectName = startupProjects?.Cast <string>().FirstOrDefault();

            if (!string.IsNullOrEmpty(startupProjectName))
            {
                if (_projectSystemCache.TryGetProjectNames(startupProjectName, out var projectName))
                {
                    DefaultNuGetProjectName = _projectSystemCache.IsAmbiguous(projectName.ShortName) ?
                                              projectName.CustomUniqueName :
                                              projectName.ShortName;
                }
            }
        }
Esempio n. 3
0
        private void SetDefaultProjectName()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // when a new solution opens, we set its startup project as the default project in NuGet Console
            var dte           = _serviceProvider.GetDTE();
            var solutionBuild = (SolutionBuild2)dte.Solution.SolutionBuild;

            if (solutionBuild.StartupProjects != null)
            {
                var startupProjects    = (IEnumerable <object>)solutionBuild.StartupProjects;
                var startupProjectName = startupProjects.Cast <string>().FirstOrDefault();
                if (!string.IsNullOrEmpty(startupProjectName))
                {
                    if (_projectSystemCache.TryGetProjectNames(startupProjectName, out ProjectNames projectName))
                    {
                        DefaultNuGetProjectName = _projectSystemCache.IsAmbiguous(projectName.ShortName) ?
                                                  projectName.CustomUniqueName :
                                                  projectName.ShortName;
                    }
                }
            }
        }