Example #1
0
        public static Version GetVisualStudioVCRedistVersion(this DevEnv visualVersion)
        {
            Version version = s_visualStudioVCRedistVersionCache.GetOrAdd(visualVersion, devEnv =>
            {
                string vsDir = visualVersion.GetVisualStudioDir();
                switch (visualVersion)
                {
                case DevEnv.vs2017:
                case DevEnv.vs2019:
                    string versionString = visualVersion.GetDefaultRedistVersion();     // default fallback
                    try
                    {
                        string toolchainFile = Path.Combine(vsDir, "VC", "Auxiliary", "Build", "Microsoft.VCRedistVersion.default.txt");
                        if (File.Exists(toolchainFile))
                        {
                            using (StreamReader file = new StreamReader(toolchainFile))
                                versionString = file.ReadLine().Trim();
                        }
                    }
                    catch { }

                    return(new Version(versionString));
                }
                throw new ArgumentOutOfRangeException("VS version not recognized " + visualVersion);
            });

            return(version);
        }
        public static Version GetVisualStudioVCRedistVersion(this DevEnv visualVersion)
        {
            Version version = s_visualStudioVCRedistVersionCache.GetOrAdd(visualVersion, devEnv =>
            {
                string vsDir         = visualVersion.GetVisualStudioDir();
                string versionString = visualVersion.GetDefaultRedistVersion(); // default fallback
                try
                {
                    string toolchainFile = Path.Combine(vsDir, "VC", "Auxiliary", "Build", "Microsoft.VCRedistVersion.default.txt");
                    if (File.Exists(toolchainFile))
                    {
                        using (StreamReader file = new StreamReader(toolchainFile))
                            versionString = file.ReadLine().Trim();
                    }
                }
                catch { }

                return(new Version(versionString));
            });

            return(version);
        }