@@ -220,25 +220,28 @@ public override void ConfigureVisualStudio(string gitBinPath, ITracer tracer)
220220 try
221221 {
222222 const string GitBinPathEnd = "\\ cmd\\ git.exe" ;
223- string [ ] gitVSRegistryKeyNames =
224- {
225- "HKEY_CURRENT_USER\\ Software\\ Microsoft\\ VSCommon\\ 15.0\\ TeamFoundation\\ GitSourceControl" ,
226- "HKEY_CURRENT_USER\\ Software\\ Microsoft\\ VSCommon\\ 16.0\\ TeamFoundation\\ GitSourceControl"
227- } ;
223+ const string VSRegistryKeyRoot = @"Software\Microsoft\VSCommon" ;
224+ const string GitVSRegistrySubKey = @"TeamFoundation\GitSourceControl" ;
228225 const string GitVSRegistryValueName = "GitPath" ;
229226
230227 if ( ! gitBinPath . EndsWith ( GitBinPathEnd ) )
231228 {
232- tracer . RelatedWarning (
233- "Unable to configure Visual Studio’s GitSourceControl regkey because invalid git.exe path found: " + gitBinPath ,
234- Keywords . Telemetry ) ;
235-
236229 return ;
237230 }
238231
239232 string regKeyValue = gitBinPath . Substring ( 0 , gitBinPath . Length - GitBinPathEnd . Length ) ;
240- foreach ( string registryKeyName in gitVSRegistryKeyNames )
233+
234+ /* Get all versions of Visual Studio that exist in the registry at least 15.0.
235+ * This attempts to future proof (current version is 17.0), but may need to be
236+ * revisited in the future if VS changes how it stores this. */
237+ var vsVersions = Registry . CurrentUser . OpenSubKey ( VSRegistryKeyRoot )
238+ ? . GetSubKeyNames ( )
239+ . Where ( name => Version . TryParse ( name , out var version ) && version . Major >= 15 )
240+ . ToArray ( ) ?? Array . Empty < string > ( ) ;
241+
242+ foreach ( string version in vsVersions )
241243 {
244+ var registryKeyName = $@ "{ Registry . CurrentUser . Name } \{ VSRegistryKeyRoot } \{ version } \{ GitVSRegistrySubKey } ";
242245 Registry . SetValue ( registryKeyName , GitVSRegistryValueName , regKeyValue ) ;
243246 }
244247 }
0 commit comments