Example #1
0
        public static VisualStudioInstance GetVisualStudioInstance()
        {
            if (VisualStudioInstanceList == null)
            {
                VisualStudioInstanceList = new List <VisualStudioInstance>();

                try
                {
                    var setupConfiguration = new SetupConfigurationClass() as ISetupConfiguration2;
                    var instanceEnumerator = setupConfiguration.EnumAllInstances();
                    var instances          = new ISetupInstance2[3];

                    instanceEnumerator.Next(instances.Length, instances, out var instancesFetched);

                    if (instancesFetched == 0)
                    {
                        return(null);
                    }

                    do
                    {
                        for (int i = 0; i < instancesFetched; i++)
                        {
                            VisualStudioInstanceList.Add(new VisualStudioInstance(instances[i]));
                        }

                        instanceEnumerator.Next(instances.Length, instances, out instancesFetched);
                    }while (instancesFetched != 0);
                }
                catch { }
            }

            return(VisualStudioInstanceList[0]);
        }
Example #2
0
        public static VisualStudioInstance GetVisualStudioInstance()
        {
            if (VisualStudioInstanceList == null)
            {
                VisualStudioInstanceList = new List <VisualStudioInstance>();

                try
                {
                    ISetupConfiguration2 setupConfiguration = new SetupConfigurationClass() as ISetupConfiguration2;

                    if (setupConfiguration != null)
                    {
                        IEnumSetupInstances instanceEnumerator = setupConfiguration.EnumAllInstances();
                        ISetupInstance2[]   instances          = new ISetupInstance2[3];

                        instanceEnumerator.Next(instances.Length, instances, out var instancesFetched);

                        if (instancesFetched == 0)
                        {
                            return(null);
                        }

                        do
                        {
                            for (int i = 0; i < instancesFetched; i++)
                            {
                                VisualStudioInstanceList.Add(new VisualStudioInstance(instances[i]));
                            }

                            instanceEnumerator.Next(instances.Length, instances, out instancesFetched);
                        }while (instancesFetched != 0);
                    }
                }
                catch { }
            }

            foreach (VisualStudioInstance instance in VisualStudioInstanceList)
            {
                if (
                    instance.HasRequiredDependency &&
                    instance.DisplayName.EndsWith("2019", StringComparison.OrdinalIgnoreCase) // HACK
                    )
                {
                    return(instance);
                }
            }

            return(null);
        }