33using System . Diagnostics ;
44using System . Globalization ;
55using System . Linq ;
6- using System . Text ;
7- using System . Threading . Tasks ;
86using GitHub . Logging ;
97using GitHub . Models ;
108using GitHub . Services ;
@@ -16,10 +14,11 @@ namespace GitHub.TeamFoundation
1614 internal class RegistryHelper
1715 {
1816 static readonly ILogger log = LogManager . ForContext < RegistryHelper > ( ) ;
19- const string TEGitKey = @"Software\Microsoft\VisualStudio\15.0\TeamFoundation\GitSourceControl" ;
17+
2018 static RegistryKey OpenGitKey ( string path )
2119 {
22- return Microsoft . Win32 . Registry . CurrentUser . OpenSubKey ( TEGitKey + "\\ " + path , true ) ;
20+ var keyName = $ "Software\\ Microsoft\\ VisualStudio\\ { MajorVersion } .0\\ TeamFoundation\\ GitSourceControl\\ { path } ";
21+ return Registry . CurrentUser . OpenSubKey ( keyName , true ) ;
2322 }
2423
2524 internal static IEnumerable < ILocalRepositoryModel > PokeTheRegistryForRepositoryList ( )
@@ -56,23 +55,24 @@ internal static string PokeTheRegistryForLocalClonePath()
5655 }
5756 }
5857
59- const string NewProjectDialogKeyPath = @"Software\Microsoft\VisualStudio\15.0\NewProjectDialog" ;
6058 const string MRUKeyPath = "MRUSettingsLocalProjectLocationEntries" ;
6159 internal static string SetDefaultProjectPath ( string path )
6260 {
61+ var newProjectDialogKeyPath = $ "Software\\ Microsoft\\ VisualStudio\\ { MajorVersion } .0\\ NewProjectDialog";
62+
6363 var old = String . Empty ;
6464 try
6565 {
66- var newProjectKey = Microsoft . Win32 . Registry . CurrentUser . OpenSubKey ( NewProjectDialogKeyPath , true ) ??
67- Microsoft . Win32 . Registry . CurrentUser . CreateSubKey ( NewProjectDialogKeyPath ) ;
66+ var newProjectKey = Registry . CurrentUser . OpenSubKey ( newProjectDialogKeyPath , true ) ??
67+ Registry . CurrentUser . CreateSubKey ( newProjectDialogKeyPath ) ;
6868
6969 if ( newProjectKey == null )
7070 {
7171 throw new GitHubLogicException (
7272 string . Format (
7373 CultureInfo . CurrentCulture ,
7474 "Could not open or create registry key '{0}'" ,
75- NewProjectDialogKeyPath ) ) ;
75+ newProjectDialogKeyPath ) ) ;
7676 }
7777
7878 using ( newProjectKey )
@@ -120,5 +120,8 @@ internal static string SetDefaultProjectPath(string path)
120120 }
121121 return old ;
122122 }
123+
124+ // Major version number of the current devenv process
125+ static int MajorVersion => Process . GetCurrentProcess ( ) . MainModule . FileVersionInfo . FileMajorPart ;
123126 }
124127}
0 commit comments