Ejemplo n.º 1
0
        public static string GetVisualStudioDir(this DevEnv visualVersion, bool ignoreVisualStudioPathOverride = false)
        {
            // TODO: Replace Tuple with ValueTuple once we support C# 8 because ValueTuple is
            //       allocated on the stack. That should be faster here.
            string visualStudioDirectory = s_visualStudioDirectories.GetOrAdd(Tuple.Create(visualVersion, ignoreVisualStudioPathOverride), devEnv =>
            {
                // First check if the visual studio path is overriden from default value.
                string pathOverride;
                if (s_visualStudioDirOverrides.TryGetValue(visualVersion, out pathOverride))
                {
                    return(pathOverride);
                }

                string installDir = Util.GetVisualStudioInstallPathFromQuery(visualVersion);
                if (string.IsNullOrEmpty(installDir))
                {
                    switch (visualVersion)
                    {
                    case DevEnv.vs2017:
                    case DevEnv.vs2019:
                        installDir = @"Microsoft Visual Studio\" + GetVSYear(visualVersion) + @"\Professional";
                        break;

                    default:
                        installDir = string.Format(@"Microsoft Visual Studio {0}", visualVersion.GetVisualVersionString());
                        break;
                    }
                    installDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), installDir);
                }
                return(Util.SimplifyPath(installDir));
            });

            return(visualStudioDirectory);
        }
Ejemplo n.º 2
0
        public static string GetVisualStudioDir(this DevEnv visualVersion)
        {
            // First check if the visual studio path is overriden from default value.
            string pathOverride;

            if (s_visualStudioDirOverrides.TryGetValue(visualVersion, out pathOverride))
            {
                return(pathOverride);
            }

            string registryKeyString = string.Format(
                @"SOFTWARE{0}\Microsoft\VisualStudio\SxS\VS7",
                Environment.Is64BitProcess ? @"\Wow6432Node" : string.Empty);

            string fallback = visualVersion == DevEnv.vs2017 ? @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional"
                                                             : @"C:\Program Files (x86)\Microsoft Visual Studio " + visualVersion.GetVisualVersionString();

            string installDir = Util.GetRegistryLocalMachineSubKeyValue(registryKeyString, visualVersion.GetVisualVersionString(), fallback);

            return(Util.SimplifyPath(installDir));
        }
Ejemplo n.º 3
0
        public static string GetVisualStudioDir(this DevEnv visualVersion, bool ignoreVisualStudioPathOverride = false)
        {
            if (!visualVersion.IsVisualStudio())
            {
                throw new Error($"{visualVersion} is not a visual studio version!");
            }

            // TODO: Replace Tuple with ValueTuple once we support C# 8 because ValueTuple is
            //       allocated on the stack. That should be faster here.
            string visualStudioDirectory = s_visualStudioDirectories.GetOrAdd(Tuple.Create(visualVersion, ignoreVisualStudioPathOverride), devEnv =>
            {
                if (!ignoreVisualStudioPathOverride)
                {
                    // First check if the visual studio path is overridden from default value.
                    string pathOverride;
                    if (s_visualStudioDirOverrides.TryGetValue(visualVersion, out pathOverride))
                    {
                        return(pathOverride);
                    }
                }

                string installDir = Util.GetVisualStudioInstallPathFromQuery(visualVersion);
                if (string.IsNullOrEmpty(installDir))
                {
                    // try again but this time including previews
                    installDir = Util.GetVisualStudioInstallPathFromQuery(visualVersion, allowPrereleaseVersions: true);
                    if (string.IsNullOrEmpty(installDir)) // arbitrary fallback
                    {
                        if (visualVersion > DevEnv.vs2015)
                        {
                            installDir = @"Microsoft Visual Studio\" + GetVSYear(visualVersion) + @"\Professional";
                        }
                        else
                        {
                            installDir = string.Format(@"Microsoft Visual Studio {0}", visualVersion.GetVisualVersionString());
                        }
                        string rootDir = Environment.GetFolderPath(visualVersion < DevEnv.vs2022 ? Environment.SpecialFolder.ProgramFilesX86 : Environment.SpecialFolder.ProgramFiles);
                        installDir     = Path.Combine(rootDir, installDir);
                    }
                }
                return(Util.SimplifyPath(installDir));
            });

            return(visualStudioDirectory);
        }
Ejemplo n.º 4
0
        public static string GetVisualStudioDir(this DevEnv visualVersion)
        {
            string registryKeyString = string.Format(
                @"SOFTWARE{0}\Microsoft\VisualStudio\SxS\VS7",
                Environment.Is64BitProcess ? @"\Wow6432Node" : string.Empty);

            string fallback = visualVersion == DevEnv.vs2017 ? @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional"
                                                             : @"C:\Program Files (x86)\Microsoft Visual Studio " + visualVersion.GetVisualVersionString();

            string installDir = Util.GetRegistryLocalMachineSubKeyValue(registryKeyString, visualVersion.GetVisualVersionString(), fallback);

            return(Util.SimplifyPath(installDir));
        }