internal static string GetProjectTypeGuids(EnvDTE.Project proj)
        {
            try
            {
                string projectTypeGuids = "";
                object service          = null;
                Microsoft.VisualStudio.Shell.Interop.IVsSolution            solution            = null;
                Microsoft.VisualStudio.Shell.Interop.IVsHierarchy           hierarchy           = null;
                Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject aggregatableProject = null;
                int result = 0;

                service  = GetService(proj.DTE, typeof(Microsoft.VisualStudio.Shell.Interop.IVsSolution));
                solution = (Microsoft.VisualStudio.Shell.Interop.IVsSolution)service;

                result = solution.GetProjectOfUniqueName(proj.UniqueName, out hierarchy);

                if (result == 0)
                {
                    aggregatableProject = (Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject)hierarchy;
                    result = aggregatableProject.GetAggregateProjectTypeGuids(out projectTypeGuids);
                }

                return(projectTypeGuids);
            }
            catch { }
            return("");
        }
        public string[] GetProjectTypeGuids(EnvDTE.Project proj)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            string projectTypeGuids = string.Empty;
            object service          = null;

            Microsoft.VisualStudio.Shell.Interop.IVsSolution  solution  = null;
            Microsoft.VisualStudio.Shell.Interop.IVsHierarchy hierarchy = null;
            IVsAggregatableProjectCorrected aggregatableProject         = null;
            int result = 0;

            service  = GetService(proj.DTE, typeof(SVsSolution));
            solution = (Microsoft.VisualStudio.Shell.Interop.IVsSolution)service;

            result = solution.GetProjectOfUniqueName(proj.UniqueName, out hierarchy);

            if (result == 0)
            {
                aggregatableProject = hierarchy as IVsAggregatableProjectCorrected;

                if (aggregatableProject != null)
                {
                    result = aggregatableProject.GetAggregateProjectTypeGuids(out projectTypeGuids);
                }
            }

            if (String.IsNullOrWhiteSpace(projectTypeGuids))
            {
                return(null);
            }

            return(projectTypeGuids.Split(';'));
        }
Exemple #3
0
            private System.Type GetTypeByName(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package, string name)
            {
                System.IServiceProvider serviceProvider = package as System.IServiceProvider;
                var typeService =
                    serviceProvider.GetService(typeof(Microsoft.VisualStudio.Shell.Design.DynamicTypeService)) as
                    Microsoft.VisualStudio.Shell.Design.DynamicTypeService;

                Microsoft.VisualStudio.Shell.Interop.IVsSolution sln =
                    serviceProvider.GetService(typeof(Microsoft.VisualStudio.Shell.Interop.IVsSolution)) as
                    Microsoft.VisualStudio.Shell.Interop.IVsSolution;

                Microsoft.VisualStudio.Shell.Interop.IVsHierarchy hier;
                sln.GetProjectOfUniqueName(DTE.ActiveDocument.ProjectItem.ContainingProject.UniqueName, out hier);

                return(typeService.GetTypeResolutionService(hier).GetType(name, true));
            }