Пример #1
0
        public static string GetVisualStudioVCRootPath(this DevEnv visualVersion)
        {
            string visualStudioVCRootPath = s_visualStudioVCRootPathCache.GetOrAdd(visualVersion, devEnv =>
            {
                string vsDir = visualVersion.GetVisualStudioDir();
                switch (visualVersion)
                {
                case DevEnv.vs2010:
                case DevEnv.vs2012:
                case DevEnv.vs2013:
                case DevEnv.vs2015:
                    return(Path.Combine(vsDir, "VC"));

                case DevEnv.vs2017:
                case DevEnv.vs2019:
                    string compilerVersion = visualVersion.GetDefaultCompilerVersion();     // default fallback
                    try
                    {
                        string toolchainFile = Path.Combine(vsDir, "VC", "Auxiliary", "Build", "Microsoft.VCToolsVersion.default.txt");
                        if (File.Exists(toolchainFile))
                        {
                            using (StreamReader file = new StreamReader(toolchainFile))
                                compilerVersion = file.ReadLine().Trim();
                        }
                    }
                    catch { }

                    return(Path.Combine(vsDir, @"VC\Tools\MSVC", compilerVersion));
                }
                throw new ArgumentOutOfRangeException("VS version not recognized " + visualVersion);
            });

            return(visualStudioVCRootPath);
        }
Пример #2
0
        public static Version GetVisualStudioVCToolsVersion(this DevEnv visualVersion)
        {
            if (!visualVersion.IsVisualStudio())
            {
                throw new Error($"{visualVersion} is not a visual studio version!");
            }

            Version version = s_visualStudioVCToolsVersionCache.GetOrAdd(visualVersion, devEnv =>
            {
                string versionString = visualVersion.GetDefaultCompilerVersion(); // default fallback
                try
                {
                    string toolchainFile = Path.Combine(visualVersion.GetVisualStudioDir(), "VC", "Auxiliary", "Build", "Microsoft.VCToolsVersion.default.txt");
                    if (File.Exists(toolchainFile))
                    {
                        using (StreamReader file = new StreamReader(toolchainFile))
                            versionString = file.ReadLine().Trim();
                    }
                }
                catch { }

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

            return(version);
        }