|
1 | 1 | using System; |
2 | 2 | using System.ComponentModel.Composition; |
| 3 | +using System.Diagnostics; |
3 | 4 | using System.Globalization; |
4 | 5 | using System.IO; |
5 | 6 | using System.Linq; |
| 7 | +using System.Text.RegularExpressions; |
6 | 8 | using GitHub.Logging; |
7 | 9 | using GitHub.VisualStudio; |
8 | 10 | using Microsoft.VisualStudio; |
| 11 | +using Microsoft.VisualStudio.Setup.Configuration; |
| 12 | +using Microsoft.VisualStudio.Shell; |
9 | 13 | using Microsoft.VisualStudio.Shell.Interop; |
10 | 14 | using Rothko; |
11 | 15 | using Serilog; |
@@ -145,22 +149,28 @@ void TryCleanupSolutionUserFiles(IOperatingSystem os, string repoPath, string sl |
145 | 149 |
|
146 | 150 | const string RegistryRootKey = @"Software\Microsoft\VisualStudio"; |
147 | 151 | const string EnvVersionKey = "EnvVersion"; |
| 152 | + const string InstallationNamePrefix = "VisualStudio/"; |
148 | 153 | string GetVSVersion() |
149 | 154 | { |
150 | 155 | var version = typeof(Microsoft.VisualStudio.Shell.ActivityLog).Assembly.GetName().Version; |
151 | 156 | var keyPath = String.Format(CultureInfo.InvariantCulture, "{0}\\{1}.{2}_Config\\SplashInfo", RegistryRootKey, version.Major, version.Minor); |
152 | 157 | try |
153 | 158 | { |
154 | | - using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(keyPath)) |
| 159 | + if (version.Major == 14) |
155 | 160 | { |
156 | | - var value = (string)key.GetValue(EnvVersionKey, String.Empty); |
157 | | - if (!String.IsNullOrEmpty(value)) |
158 | | - return value; |
| 161 | + using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(keyPath)) |
| 162 | + { |
| 163 | + var value = (string)key.GetValue(EnvVersionKey, String.Empty); |
| 164 | + if (!String.IsNullOrEmpty(value)) |
| 165 | + return value; |
| 166 | + } |
| 167 | + } |
| 168 | + else |
| 169 | + { |
| 170 | + var setupConfiguration = new SetupConfiguration(); |
| 171 | + var setupInstance = setupConfiguration.GetInstanceForCurrentProcess(); |
| 172 | + return setupInstance.GetInstallationName().TrimPrefix(InstallationNamePrefix); |
159 | 173 | } |
160 | | - // fallback to poking the CommonIDE assembly, which most closely follows the advertised version. |
161 | | - var asm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName.StartsWith("Microsoft.VisualStudio.CommonIDE", StringComparison.OrdinalIgnoreCase)); |
162 | | - if (asm != null) |
163 | | - return asm.GetName().Version.ToString(); |
164 | 174 | } |
165 | 175 | catch(Exception ex) |
166 | 176 | { |
|
0 commit comments