public Vs2017SetupConfig()
        {
            try
            {
                // Try to CoCreate the class object.
                _setupConfig = new SetupConfiguration();
            }
            catch (COMException ex) when(ex.HResult == REGDB_E_CLASSNOTREG)
            {
                // Try to get the class object using app-local call.
                var result = GetSetupConfiguration(out _setupConfig, IntPtr.Zero);

                if (result < 0)
                {
                    throw new COMException("Failed to get query", result);
                }
            }

            var setupConfig2 = (ISetupConfiguration2)_setupConfig;
            var e            = setupConfig2.EnumAllInstances();
            var helper       = (ISetupHelper)_setupConfig;

            int fetched;
            var instances = new ISetupInstance[1];

            do
            {
                e.Next(1, instances, out fetched);
                if (fetched > 0)
                {
                    var instance2    = (ISetupInstance2)instances[0];
                    var instanceInfo = new VSInstanceInfo
                    {
                        Id            = instance2.GetInstanceId(),
                        Name          = instance2.GetInstallationName(),
                        Version       = instance2.GetInstallationVersion(),
                        DispName      = instance2.GetDisplayName(),
                        Description   = instance2.GetDescription(),
                        ResPath       = instance2.ResolvePath(),
                        EnginePath    = instance2.GetEnginePath(),
                        InstalledPath = instance2.GetInstallationPath(),
                        ProductPath   = instance2.GetProductPath()
                    };
                    _instanceInfos.Add(instanceInfo);
                }
            }while (fetched > 0);
        }
Beispiel #2
0
        public Vs2017SetupConfig()
        {
            try
            {
                _setupConfig = new SetupConfiguration();
            }
            catch (Exception ex)
            {
                throw new Exception($"Cannot create a new SetupConfiguration for Visual Studio", ex);
            }

            var setupConfig2 = (ISetupConfiguration2)_setupConfig;
            var e            = setupConfig2.EnumAllInstances();
            var helper       = (ISetupHelper)_setupConfig;

            int fetched;
            var instances = new ISetupInstance[1];

            do
            {
                e.Next(1, instances, out fetched);
                if (fetched > 0)
                {
                    var instance2    = (ISetupInstance2)instances[0];
                    var instanceInfo = new VSInstanceInfo
                    {
                        Id            = instance2.GetInstanceId(),
                        Name          = instance2.GetInstallationName(),
                        Version       = instance2.GetInstallationVersion(),
                        DispName      = instance2.GetDisplayName(),
                        Description   = instance2.GetDescription(),
                        ResPath       = instance2.ResolvePath(),
                        EnginePath    = instance2.GetEnginePath(),
                        InstalledPath = instance2.GetInstallationPath(),
                        ProductPath   = instance2.GetProductPath()
                    };
                    _instanceInfos.Add(instanceInfo);
                }
            }while (fetched > 0);
        }