src/Misc/EntityFramework.PowerShell/Migrations/Extensions/ProjectExtensions.cs
// <summary>
// Gets all aggregate project type GUIDs for the given project.
// Note that when running in Visual Studio app domain (which is how this code is used in
// production) a shellVersion of 10 is fine because VS has binding redirects to cause the
// latest version to be loaded. When running tests is may be desirable to explicitly pass
// a different version. See CodePlex 467.
// </summary>
Gets all aggregate project type GUIDs for the given project.
Note that when running in Visual Studio app domain (which is how this code is used in
production) a shellVersion of 10 is fine because VS has binding redirects to cause the
latest version to be loaded. When running tests is may be desirable to explicitly pass
a different version.
Gets all aggregate project type GUIDs for the given project . Note that when running in Visual Studio app domain ( which is how this code is used in production ) a shellVersion of 10 is fine because VS has binding redirects to cause the latest version to be loaded . When running tests is may be desirable to explicitly pass a different version .
public static IEnumerable<string> GetProjectTypes(this Project project, int shellVersion = 10)
        {
            DebugCheck.NotNull(project);
            IVsHierarchy hierarchy;
            var serviceProviderType = Type.GetType(string.Format(
                "Microsoft.VisualStudio.Shell.ServiceProvider, Microsoft.VisualStudio.Shell, Version={0}.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
                shellVersion));
            Debug.Assert(serviceProviderType != null);
            var serviceProvider = (IServiceProvider)Activator.CreateInstance(
                serviceProviderType,
                (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)project.DTE);
            var solution = (IVsSolution)serviceProvider.GetService(typeof(IVsSolution));
            var hr = solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy);
            if (hr != S_OK)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            string projectTypeGuidsString;
            var aggregatableProject = (IVsAggregatableProject)hierarchy;
            hr = aggregatableProject.GetAggregateProjectTypeGuids(out projectTypeGuidsString);
            if (hr != S_OK)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            return projectTypeGuidsString.Split(';');
        }
public static IEnumerable < string > GetProjectTypes ( this Project project , int shellVersion = 10 ) { DebugCheck . NotNull ( project ) ; IVsHierarchy hierarchy ; var serviceProviderType = Type . GetType ( string . Format ( " " , shellVersion ) ) ; Debug . Assert ( serviceProviderType != null ) ; var serviceProvider = ( IServiceProvider ) Activator . CreateInstance ( serviceProviderType , ( Microsoft . VisualStudio . OLE . Interop . IServiceProvider ) project . DTE ) ; var solution = ( IVsSolution ) serviceProvider . GetService ( typeof ( IVsSolution ) ) ; var hr = solution . GetProjectOfUniqueName ( project . UniqueName , out hierarchy ) ; if ( hr != S_OK ) { Marshal . ThrowExceptionForHR ( hr ) ; } string projectTypeGuidsString ; var aggregatableProject = ( IVsAggregatableProject ) hierarchy ; hr = aggregatableProject . GetAggregateProjectTypeGuids ( out projectTypeGuidsString ) ; if ( hr != S_OK ) { Marshal . ThrowExceptionForHR ( hr ) ; } return projectTypeGuidsString . Split ( ' ' ) ; }
Gets all aggregate project type GUIDs for the given project.
Gets all aggregate project type GUIDs for the given project .
Project
this
shellVersion
int