using System; using Microsoft.Win32; namespace Cosmos.Build.Installer { public static class Paths { /// /// Version of Visual Studio for which paths should be detected. /// private static VsVersion vsVersion; public static readonly string ProgFiles32; public static readonly string ProgFiles64; public static readonly string Windows; static Paths() { if (Global.IsX64) { ProgFiles32 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); ProgFiles64 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); } else { ProgFiles32 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); } UpdateVsPath(); Windows = Environment.GetFolderPath(Environment.SpecialFolder.Windows); } /// /// Gets path where Visual Studio installed /// public static string VSInstall { get; private set; } /// /// Version of Visual Studio for which paths should be detected. /// public static VsVersion VsVersion { get { return vsVersion; } set { vsVersion = value; UpdateVsPath(); } } /// /// Updates path to VS version /// private static void UpdateVsPath() { // The Install Dir will pickup only the Visual Studio 2013/2015 path currently. RegistryKey key; string vsVersionCode; switch (VsVersion) { case VsVersion.Vs2013: vsVersionCode = "12.0"; break; case VsVersion.Vs2015: vsVersionCode = "14.0"; break; default: throw new NotSupportedException("Versions of VS other then 2013 and 2015 not supported."); } var registryKey = string.Format( @"SOFTWARE{0}\microsoft\VisualStudio\{1}", Environment.Is64BitOperatingSystem ? @"\Wow6432Node" : "", vsVersionCode); key = Registry.LocalMachine.OpenSubKey(registryKey); VSInstall = key.GetValue("InstallDir") as string; } } }