예제 #1
0
        /// <summary>
        /// Returns the export T of the startup projects if those projects support the specified capabilities
        /// </summary>
        public ImmutableArray <T> GetExportFromDotNetStartupProjects <T>(string capabilityMatch) where T : class
        {
#pragma warning disable RS0030 // Do not used banned APIs
            EnvDTE.DTE dte = ServiceProvider.GetService <EnvDTE.DTE, EnvDTE.DTE>();
#pragma warning restore RS0030 // Do not used banned APIs
            if (dte != null)
            {
                if (dte.Solution.SolutionBuild.StartupProjects is Array startupProjects && startupProjects.Length > 0)
                {
#pragma warning disable RS0030 // Do not used banned APIs
                    IVsSolution sln = ServiceProvider.GetService <IVsSolution, SVsSolution>();
#pragma warning restore RS0030 // Do not used banned APIs
                    var results = PooledArray <T> .GetInstance();

                    foreach (string projectName in startupProjects)
                    {
                        sln.GetProjectOfUniqueName(projectName, out IVsHierarchy hier);
                        if (hier != null && hier.IsCapabilityMatch(capabilityMatch))
                        {
                            string projectPath = hier.GetProjectFilePath();
                            results.Add(ProjectExportProvider.GetExport <T>(projectPath));
                        }
                    }
                    return(results.ToImmutableAndFree());
                }
            }
            return(ImmutableArray <T> .Empty);
        }
예제 #2
0
        /// <summary>
        /// Returns an unconfigured project level contexts for given project file path.
        /// </summary>
        /// <param name="projectFilePath">Full path to project path.</param>
        /// <returns>
        /// Instance of <see cref="IDependenciesGraphProjectContext"/> or null if context was not found for given project file.
        /// </returns>
        public IDependenciesGraphProjectContext GetProjectContext(string projectFilePath)
        {
            if (string.IsNullOrEmpty(projectFilePath))
            {
                throw new ArgumentException(nameof(projectFilePath));
            }

            IDependenciesGraphProjectContext context = null;

            if (ProjectContexts.TryGetValue(projectFilePath, out context))
            {
                return(context);
            }

            context = ProjectExportProvider.GetExport <IDependenciesGraphProjectContext>(projectFilePath);
            if (context == null)
            {
                return(null);
            }

            ProjectContexts[projectFilePath] = context;
            context.ProjectContextChanged   += OnProjectContextChanged;
            context.ProjectContextUnloaded  += OnProjectContextUnloaded;

            return(context);
        }
 /// <summary>
 /// Returns the export T of the startup project if that project supports the specified capabilities
 /// </summary>
 public T GetExportFromSingleDotNetStartupProject <T>(string capabilityMatch) where T : class
 {
     EnvDTE.DTE dte = ServiceProvider.GetService <EnvDTE.DTE, EnvDTE.DTE>();
     if (dte != null)
     {
         if (dte.Solution.SolutionBuild.StartupProjects is Array startupProjects && startupProjects.Length == 1)
         {
             IVsSolution sln = ServiceProvider.GetService <IVsSolution, SVsSolution>();
             foreach (string projectName in startupProjects)
             {
                 sln.GetProjectOfUniqueName(projectName, out IVsHierarchy hier);
                 if (hier != null && hier.IsCapabilityMatch(capabilityMatch))
                 {
                     string projectPath = hier.GetProjectFilePath();
                     return(ProjectExportProvider.GetExport <T>(projectPath));
                 }
             }
         }
     }
     return(null);
 }
예제 #4
0
        public IDependenciesSnapshotProvider GetSnapshotProvider(string projectFilePath)
        {
            if (string.IsNullOrEmpty(projectFilePath))
            {
                throw new ArgumentException(nameof(projectFilePath));
            }

            lock (_snapshotProvidersLock)
            {
                if (SnapshotProviders.TryGetValue(projectFilePath, out IDependenciesSnapshotProvider snapshotProvider))
                {
                    return(snapshotProvider);
                }

                snapshotProvider = ProjectExportProvider.GetExport <IDependenciesSnapshotProvider>(projectFilePath);
                if (snapshotProvider != null)
                {
                    RegisterSnapshotProvider(snapshotProvider);
                }

                return(snapshotProvider);
            }
        }
 /// <summary>
 /// Returns the export T of the startup projects if those projects support the specified capabilities
 /// </summary>
 public ImmutableArray <T> GetExportFromDotNetStartupProjects <T>(string capabilityMatch) where T : class
 {
     EnvDTE.DTE dte = ServiceProvider.GetService <EnvDTE.DTE, EnvDTE.DTE>();
     if (dte != null)
     {
         if (dte.Solution.SolutionBuild.StartupProjects is Array startupProjects && startupProjects.Length > 0)
         {
             IVsSolution sln = ServiceProvider.GetService <IVsSolution, SVsSolution>();
             ImmutableArray <T> .Builder results = ImmutableArray.CreateBuilder <T>();
             foreach (string projectName in startupProjects)
             {
                 sln.GetProjectOfUniqueName(projectName, out IVsHierarchy hier);
                 if (hier != null && hier.IsCapabilityMatch(capabilityMatch))
                 {
                     string projectPath = hier.GetProjectFilePath();
                     results.Add(ProjectExportProvider.GetExport <T>(projectPath));
                 }
             }
             return(results.ToImmutable());
         }
     }
     return(ImmutableArray <T> .Empty);
 }