private static void GetInstalledVisualStudios(VisualStudioVersion vsVersion, Dictionary <VisualStudioVersion, VisualStudioPath[]> versions) { var requiredWorkloads = new[] { "Microsoft.VisualStudio.Workload.ManagedGame" }; var raw = VisualStudioUtil.FindVisualStudioDevEnvPaths((int)vsVersion, requiredWorkloads); var visualStudioPaths = VisualStudioUtil.ParseRawDevEnvPaths(raw) .Where(vs => !requiredWorkloads.Except(vs.Workloads).Any()) // All required workloads must be present .Select(vs => new VisualStudioPath(vs.DevEnvPath, vs.Edition)) .ToArray(); if (visualStudioPaths.Length != 0) { versions[vsVersion] = visualStudioPaths; } }
private static IDictionary <VisualStudioVersion, VisualStudioPath[]> GetInstalledVisualStudios() { Dictionary <VisualStudioVersion, VisualStudioPath[]> dictionary = new Dictionary <VisualStudioVersion, VisualStudioPath[]>(); if (SyncVS.SolutionSynchronizationSettings.IsWindows) { IEnumerator enumerator = Enum.GetValues(typeof(VisualStudioVersion)).GetEnumerator(); try { while (enumerator.MoveNext()) { VisualStudioVersion visualStudioVersion = (VisualStudioVersion)enumerator.Current; if (visualStudioVersion <= VisualStudioVersion.VisualStudio2015) { try { string text = Environment.GetEnvironmentVariable(string.Format("VS{0}0COMNTOOLS", (int)visualStudioVersion)); if (!string.IsNullOrEmpty(text)) { string path = Paths.Combine(new string[] { text, "..", "IDE", "devenv.exe" }); if (File.Exists(path)) { dictionary[visualStudioVersion] = new VisualStudioPath[] { new VisualStudioPath(path, "") }; continue; } } text = SyncVS.GetRegistryValue(string.Format("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\{0}.0", (int)visualStudioVersion), "InstallDir"); if (string.IsNullOrEmpty(text)) { text = SyncVS.GetRegistryValue(string.Format("HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\VisualStudio\\{0}.0", (int)visualStudioVersion), "InstallDir"); } if (!string.IsNullOrEmpty(text)) { string path2 = Paths.Combine(new string[] { text, "devenv.exe" }); if (File.Exists(path2)) { dictionary[visualStudioVersion] = new VisualStudioPath[] { new VisualStudioPath(path2, "") }; continue; } } text = SyncVS.GetRegistryValue(string.Format("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\{0}.0\\Debugger", (int)visualStudioVersion), "FEQARuntimeImplDll"); if (!string.IsNullOrEmpty(text)) { string text2 = SyncVS.DeriveVisualStudioPath(text); if (!string.IsNullOrEmpty(text2) && File.Exists(text2)) { dictionary[visualStudioVersion] = new VisualStudioPath[] { new VisualStudioPath(SyncVS.DeriveVisualStudioPath(text), "") }; } } } catch { } } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } string[] array = VisualStudioUtil.FindVisualStudioDevEnvPaths(15, "Microsoft.VisualStudio.Workload.ManagedGame"); if (array != null && array.Length > 0) { VisualStudioPath[] array2 = new VisualStudioPath[array.Length / 2]; for (int i = 0; i < array.Length / 2; i++) { array2[i] = new VisualStudioPath(array[i * 2], array[i * 2 + 1]); } dictionary[VisualStudioVersion.VisualStudio2017] = array2; } } return(dictionary); }
/// <summary> /// Detects Visual Studio installations using the Windows registry /// </summary> /// <returns> /// The detected Visual Studio installations /// </returns> private static IDictionary <VisualStudioVersion, VisualStudioPath[]> GetInstalledVisualStudios() { var versions = new Dictionary <VisualStudioVersion, VisualStudioPath[]>(); if (SolutionSynchronizationSettings.IsWindows) { foreach (VisualStudioVersion version in Enum.GetValues(typeof(VisualStudioVersion))) { if (version > VisualStudioVersion.VisualStudio2015) { continue; } try { // Try COMNTOOLS environment variable first string key = Environment.GetEnvironmentVariable(string.Format("VS{0}0COMNTOOLS", (int)version)); if (!string.IsNullOrEmpty(key)) { string path = UnityEditor.Utils.Paths.Combine(key, "..", "IDE", "devenv.exe"); if (File.Exists(path)) { versions[version] = new[] { new VisualStudioPath(path) }; continue; } } // Try the proper registry key key = GetRegistryValue( string.Format(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\{0}.0", (int)version), "InstallDir"); // Try to fallback to the 32bits hive if (string.IsNullOrEmpty(key)) { key = GetRegistryValue( string.Format(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\{0}.0", (int)version), "InstallDir"); } if (!string.IsNullOrEmpty(key)) { string path = UnityEditor.Utils.Paths.Combine(key, "devenv.exe"); if (File.Exists(path)) { versions[version] = new[] { new VisualStudioPath(path) }; continue; } } // Fallback to debugger key key = GetRegistryValue( // VS uses this key for the local debugger path string.Format(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\{0}.0\Debugger", (int)version), "FEQARuntimeImplDll"); if (!string.IsNullOrEmpty(key)) { string path = DeriveVisualStudioPath(key); if (!string.IsNullOrEmpty(path) && File.Exists(path)) { versions[version] = new[] { new VisualStudioPath(DeriveVisualStudioPath(key)) } } ; } } catch { // This can happen with a registry lookup failure } } var requiredWorkloads = new[] { "Microsoft.VisualStudio.Workload.ManagedGame" }; var raw = VisualStudioUtil.FindVisualStudioDevEnvPaths((int)VisualStudioVersion.VisualStudio2017, requiredWorkloads); var visualStudioPaths = VisualStudioUtil.ParseRawDevEnvPaths(raw) .Where(vs => !requiredWorkloads.Except(vs.Workloads).Any()) // All required workloads must be present .Select(vs => new VisualStudioPath(vs.DevEnvPath, vs.Edition)) .ToArray(); if (visualStudioPaths.Length != 0) { versions[VisualStudioVersion.VisualStudio2017] = visualStudioPaths; } } return(versions); }