public IEnumerable <Guid> GetAggregateProjectKinds(IVsHierarchy hierarchy)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException(nameof(hierarchy));
            }

            IVsAggregatableProjectCorrected aggregatableProject = hierarchy as IVsAggregatableProjectCorrected;

            if (aggregatableProject == null)
            {
                yield break;
            }

            string guidStrings;

            if (ErrorHandler.Succeeded(aggregatableProject.GetAggregateProjectTypeGuids(out guidStrings)))
            {
                foreach (var guidStr in guidStrings.Split(';'))
                {
                    Guid guid;
                    if (Guid.TryParse(guidStr, out guid))
                    {
                        yield return(guid);
                    }
                }
            }
        }
        private IEnumerable <Guid> GetAggregateProjectKindsIterator(IVsHierarchy hierarchy)
        {
            // TODO: is this relevant for core projects?

            IVsAggregatableProjectCorrected aggregatableProject = hierarchy as IVsAggregatableProjectCorrected;

            if (aggregatableProject == null)
            {
                yield break;
            }

            string guidStrings;

            if (ErrorHandler.Succeeded(aggregatableProject.GetAggregateProjectTypeGuids(out guidStrings)))
            {
                foreach (var guidStr in guidStrings.Split(';'))
                {
                    Guid guid;
                    if (Guid.TryParse(guidStr, out guid))
                    {
                        yield return(guid);
                    }
                }
            }
        }
        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 #4
0
        private LaunchType GetProjectLaunchType(Project project)
        {
            IVsSolution solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution));

            IVsHierarchy hierarchy = null;

            solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy);

            IVsAggregatableProjectCorrected AP = hierarchy as IVsAggregatableProjectCorrected;
            string projTypeGuids = null;

            AP.GetAggregateProjectTypeGuids(out projTypeGuids);
            projTypeGuids = projTypeGuids.ToUpper();

            if (projTypeGuids.Contains(WEB_SITE_PROJECT_TYPE_GUID.ToUpper()))
            {
                return(LaunchType.WebSite);
            }
            else if (projTypeGuids.Contains(WEB_APPLICATION_PROJECT_SUBTYPE_GUID.ToUpper()))
            {
                return(LaunchType.WebApplication);
            }

            return(LaunchType.Assembly);
        }
        /// <summary>
        /// Get weather the project is portable class library or not.
        /// </summary>
        /// <param name="project"></param>
        /// <param name="solution"></param>
        /// <returns></returns>
        public static bool IsPclProject(this Project project, IVsSolution solution)
        {
            solution.GetProjectOfUniqueName(project.UniqueName, out IVsHierarchy hierarchy);
            IVsAggregatableProjectCorrected ap = hierarchy as IVsAggregatableProjectCorrected;
            string projTypeGuids = null;

            ap?.GetAggregateProjectTypeGuids(out projTypeGuids);
            return(projTypeGuids == Constants.PclProjectTypeGuids);
        }
        public virtual void FreeInterfaces()
        {
            if (this._menuService != null)
            {
                OleMenuCommandService tempService = this._menuService;
                this._menuService = null;
                tempService.Dispose();
            }

            _innerOleCommandTarget      = null;
            _innerVsAggregatableProject = null;
            _innerVsUIHierarchy         = null;
            _innerVsHierarchy           = null;
        }
        /// <include file='doc\FlavoredProject.uex' path='docs/doc[@for="FlavoredProject.SetInnerProject"]/*' />
        /// <devdoc>
        /// This is were all QI for interface on the inner object should happen
        /// Then set the inner project
        /// wait for InitializeForOuter to be called to do the real initialization
        /// </devdoc>
        protected virtual void SetInnerProject(IntPtr innerIUnknown)
        {
            object inner = null;

            inner = Marshal.GetObjectForIUnknown(innerIUnknown);

            // Keep a reference to each interface we want to call on the inner project
            // we must do it now as once we call SetInner the AddRef would be forwarded to ourselves
            _innerVsAggregatableProject = inner as IVsAggregatableProjectCorrected;
            Debug.Assert(inner != null, "Failed to retrieve IVsAggregatableProjectCorrected from inner Project");
            _innerVsHierarchy   = (IVsHierarchy)inner;
            _innerVsUIHierarchy = (IVsUIHierarchy)inner;
            // "As" should return null without throwing in the event the base project does not implement the interface
            _innerOleCommandTarget = inner as IOleCommandTarget;

            // Setup our menu command service
            if (this.serviceProvider == null)
            {
                throw new NotSupportedException("serviceProvider should have been set before SetInnerProject gets called.");
            }
            _menuService = new OleMenuCommandService(this, _innerOleCommandTarget);

            // Pass the inner project pointer to the VisualStudio.ProjectAggregator2 object. This native object
            // has a special implementation of QueryInterface that delegates first to our managed FlavoredProjectBase
            // derived object and then to the inner project (either the base project or the next project flavor down).
            IntPtr thisIUnknown = IntPtr.Zero;
            IVsProjectAggregator2 vsProjectAggregator2 = null;

            try
            {
                thisIUnknown         = Marshal.GetIUnknownForObject(this);
                vsProjectAggregator2 = (IVsProjectAggregator2)Marshal.GetObjectForIUnknown(thisIUnknown);
                if (vsProjectAggregator2 != null)
                {
                    vsProjectAggregator2.SetInner(innerIUnknown);
                }
            }
            finally
            {
                if (thisIUnknown != IntPtr.Zero)
                {
                    Marshal.Release(thisIUnknown);
                }
            }
        }
        public virtual void FreeInterfaces()
        {
            this._menuService = null;

            if (_innerOleCommandTarget != null)
            {
                if (Marshal.IsComObject(_innerOleCommandTarget))
                {
                    Marshal.ReleaseComObject(_innerOleCommandTarget);
                }
                _innerOleCommandTarget = null;
            }

            if (_innerVsAggregatableProject != null)
            {
                if (Marshal.IsComObject(_innerVsAggregatableProject))
                {
                    Marshal.ReleaseComObject(_innerVsAggregatableProject);
                }
                _innerVsAggregatableProject = null;
            }

            if (_innerVsUIHierarchy != null)
            {
                if (Marshal.IsComObject(_innerVsUIHierarchy))
                {
                    Marshal.ReleaseComObject(_innerVsUIHierarchy);
                }
                _innerVsUIHierarchy = null;
            }

            if (_innerVsHierarchy != null)
            {
                if (Marshal.IsComObject(_innerVsHierarchy))
                {
                    Marshal.ReleaseComObject(_innerVsHierarchy);
                }
                _innerVsHierarchy = null;
            }
        }
Exemple #9
0
        private LaunchType GetProjectLaunchType(Project project)
        {
            try {
                IVsSolution solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution));

                IVsHierarchy hierarchy = null;
                solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy);

                IVsAggregatableProjectCorrected AP = hierarchy as IVsAggregatableProjectCorrected;
                string projTypeGuids = null;

                // e.g. .NET core applications are not aggregable
                if (AP != null)
                {
                    AP.GetAggregateProjectTypeGuids(out projTypeGuids);
                    projTypeGuids = projTypeGuids.ToUpper();

                    if (projTypeGuids.Contains(WEB_SITE_PROJECT_TYPE_GUID.ToUpper()))
                    {
                        return(LaunchType.WebSite);
                    }
                    if (projTypeGuids.Contains(WEB_APPLICATION_PROJECT_SUBTYPE_GUID.ToUpper()))
                    {
                        return(LaunchType.WebApplication);
                    }
                }

                if (new AssemblyLauchConfig(project).IsValid())
                {
                    return(LaunchType.Assembly);
                }
            }
            catch (Exception ex)
            {
                context.log(Context.LOG_ERROR + "Error while resolving project launch type: " + ex);
            }

            return(LaunchType.Unknown);
        }
Exemple #10
0
        private async Task DebugProjectTypes()
        {
            //await Task.CompletedTask;
            //return;

            try
            {
                // TODO: Does this class ever need to be tested, so stub this?
                // TODO: Possibly move to other package instance thing all together?
                await JoinableTaskFactory.SwitchToMainThreadAsync();

                dte = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE));
                var proj1 = dte.Solution.Projects.Item(1);
                var proj2 = dte.Solution.Projects.Item(2);

                var proj1Name = proj1.UniqueName;
                var proj2Name = proj2.UniqueName;
                solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution));
                IVsHierarchy hier1;
                IVsHierarchy hier2;
                solution.GetProjectOfUniqueName(proj1Name, out hier1);
                solution.GetProjectOfUniqueName(proj2Name, out hier2);

                var items = new[]
                {
                    proj1.ProjectItems.Item(1),
                    proj1.ProjectItems.Item(2),
                    proj1.ProjectItems.Item(3),
                    proj1.ProjectItems.Item(4),
                };

                var item = items[0];

                Func <Properties, IDictionary <string, object> > getProps = ps => ps.Cast <Property>().ToDictionary(x => x.Name, x =>
                {
                    try
                    {
                        return(x.Value);
                    }
                    catch (Exception e)
                    {
                        return("Error: " + e.Message);
                    }
                });

                var projProps  = getProps(proj1.Properties);
                var proj2Props = getProps(proj2.Properties);

                var props = getProps(item.Properties);

                var item2  = dte.Solution.Projects.Item(2).ProjectItems.Item(1);
                var props2 = getProps(item2.Properties);

                var genProp  = item.Properties.Cast <Property>().FirstOrDefault(x => x.Name == "Generator");
                var toolProp = item.Properties.Cast <Property>().FirstOrDefault(x => x.Name == "CustomTool");

                if (genProp != null)
                {
                    genProp.Value = "ARMLinker";
                }

                if (toolProp != null)
                {
                    toolProp.Value = "ARMLinker";
                }

                return;

                var interfaces = SupportedInterfaces(hier1);

                IVsAggregatableProjectCorrected ap1 = hier1 as IVsAggregatableProjectCorrected;
                IVsAggregatableProjectCorrected ap2 = hier2 as IVsAggregatableProjectCorrected;
                ap1.GetAggregateProjectTypeGuids(out var guids1);
                ap2.GetAggregateProjectTypeGuids(out var guids2);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                Debug.WriteLine(e.StackTrace);
            }
        }
        /// <include file='doc\FlavoredProject.uex' path='docs/doc[@for="FlavoredProject.SetInnerProject"]/*' />
        /// <devdoc>
        /// This is were all QI for interface on the inner object should happen
        /// Then set the inner project
        /// wait for InitializeForOuter to be called to do the real initialization
        /// </devdoc>
        protected virtual void SetInnerProject(IntPtr innerIUnknown)
        {
            object inner = null;

            inner = Marshal.GetObjectForIUnknown(innerIUnknown);

            // Keep a reference to each interface we want to call on the inner project
            // we must do it now as once we call SetInner the AddRef would be forwarded to ourselves
            _innerVsAggregatableProject = inner as IVsAggregatableProjectCorrected;
            Debug.Assert(inner != null, "Failed to retrieve IVsAggregatableProjectCorrected from inner Project");
            _innerVsHierarchy = (IVsHierarchy)inner;
            _innerVsUIHierarchy = (IVsUIHierarchy)inner;
            // "As" should return null without throwing in the event the base project does not implement the interface
            _innerOleCommandTarget = inner as IOleCommandTarget;

            // Setup our menu command service
            if (this.serviceProvider == null)
                throw new NotSupportedException("serviceProvider should have been set before SetInnerProject gets called.");
            _menuService = new OleMenuCommandService(this, _innerOleCommandTarget);

            // Pass the inner project pointer to the VisualStudio.ProjectAggregator2 object. This native object
            // has a special implementation of QueryInterface that delegates first to our managed FlavoredProjectBase
            // derived object and then to the inner project (either the base project or the next project flavor down).
            IntPtr thisIUnknown = IntPtr.Zero;
            IVsProjectAggregator2 vsProjectAggregator2 = null;
            try
            {
                thisIUnknown = Marshal.GetIUnknownForObject(this);
                vsProjectAggregator2 = (IVsProjectAggregator2)Marshal.GetObjectForIUnknown(thisIUnknown);
                if (vsProjectAggregator2 != null)
                    vsProjectAggregator2.SetInner(innerIUnknown);
            }
            finally
            {
                if (thisIUnknown != IntPtr.Zero)
                    Marshal.Release(thisIUnknown);
            }
        }
        public virtual void FreeInterfaces()
        {
            this._menuService = null;

            if (_innerOleCommandTarget != null)
            {
                if (Marshal.IsComObject(_innerOleCommandTarget))
                    Marshal.ReleaseComObject(_innerOleCommandTarget);
                _innerOleCommandTarget = null;
            }

            if (_innerVsAggregatableProject != null)
            {
                if (Marshal.IsComObject(_innerVsAggregatableProject))
                    Marshal.ReleaseComObject(_innerVsAggregatableProject);
                _innerVsAggregatableProject = null;
            }

            if (_innerVsUIHierarchy != null)
            {
                if (Marshal.IsComObject(_innerVsUIHierarchy))
                    Marshal.ReleaseComObject(_innerVsUIHierarchy);
                _innerVsUIHierarchy = null;
            }

            if (_innerVsHierarchy != null)
            {
                if (Marshal.IsComObject(_innerVsHierarchy))
                    Marshal.ReleaseComObject(_innerVsHierarchy);
                _innerVsHierarchy = null;
            }
        }