88using GitHub . Logging ;
99using GitHub . VisualStudio ;
1010using Microsoft . VisualStudio ;
11+ using Microsoft . VisualStudio . Setup . Configuration ;
12+ using Microsoft . VisualStudio . Shell ;
1113using Microsoft . VisualStudio . Shell . Interop ;
1214using Rothko ;
1315using Serilog ;
@@ -147,6 +149,7 @@ void TryCleanupSolutionUserFiles(IOperatingSystem os, string repoPath, string sl
147149
148150 const string RegistryRootKey = @"Software\Microsoft\VisualStudio" ;
149151 const string EnvVersionKey = "EnvVersion" ;
152+ const string InstallationNamePrefix = "VisualStudio/" ;
150153 string GetVSVersion ( )
151154 {
152155 var version = typeof ( Microsoft . VisualStudio . Shell . ActivityLog ) . Assembly . GetName ( ) . Version ;
@@ -164,30 +167,9 @@ string GetVSVersion()
164167 }
165168 else
166169 {
167- var os = serviceProvider . TryGetService < IOperatingSystem > ( ) ;
168- var devenv = Path . GetDirectoryName ( Process . GetCurrentProcess ( ) . MainModule . FileName ) ;
169-
170- // C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances
171- var pathToInstallationData = Path . Combine ( os . Environment . GetFolderPath ( System . Environment . SpecialFolder . CommonApplicationData ) ,
172- "Microsoft" , "VisualStudio" , "Packages" , "_Instances" ) ;
173-
174- var regexVersion = new Regex ( @"""productDisplayVersion"":""([^""]+)""" ) ;
175- var regexPath = new Regex ( @"""installationPath"":""([^""]+)""" ) ;
176-
177- foreach ( var dir in os . Directory . EnumerateDirectories ( pathToInstallationData ) )
178- {
179- var data = os . File . ReadAllText ( Path . Combine ( dir , "state.json" ) , System . Text . Encoding . UTF8 ) ;
180- if ( regexPath . IsMatch ( data ) && regexVersion . IsMatch ( data ) )
181- {
182- var path = regexPath . Match ( data ) . Groups [ 1 ] . Value ;
183- path = path . Replace ( "\\ \\ " , "\\ " ) ;
184- if ( devenv . StartsWith ( path , StringComparison . OrdinalIgnoreCase ) )
185- {
186- var value = regexVersion . Match ( data ) . Groups [ 1 ] . Value ;
187- return value ;
188- }
189- }
190- }
170+ var setupConfiguration = new SetupConfiguration ( ) ;
171+ var setupInstance = setupConfiguration . GetInstanceForCurrentProcess ( ) ;
172+ return setupInstance . GetInstallationName ( ) . TrimPrefix ( InstallationNamePrefix ) ;
191173 }
192174 }
193175 catch ( Exception ex )
0 commit comments