Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit ff35699

Browse files
committed
Grab VS version from registry
1 parent decd642 commit ff35699

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

src/GitHub.Exports/Services/IVSServices.cs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace GitHub.Services
55
{
66
public interface IVSServices
77
{
8+
string VSVersion { get; }
9+
810
void ActivityLogMessage(string message);
911
void ActivityLogWarning(string message);
1012
void ActivityLogError(string message);

src/GitHub.Exports/Services/Services.cs

-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ public static IVsOutputWindowPane OutputWindowPane
8484

8585
public static IVsUIShell UIShell => GetGlobalService<SVsUIShell, IVsUIShell>();
8686

87-
public static string VisualStudioVersion => Dte.Version;
88-
8987
public static IVsActivityLog GetActivityLog(this IServiceProvider provider)
9088
{
9189
return GetGlobalService<SVsActivityLog, IVsActivityLog>(provider);

src/GitHub.Exports/Services/UsageTracker.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class UsageTracker : IUsageTracker
2424
readonly IMetricsService client;
2525
readonly IConnectionManager connectionManager;
2626
readonly IPackageSettings userSettings;
27+
readonly IVSServices vsservices;
2728
readonly DispatcherTimer timer;
2829
readonly string storePath;
2930

@@ -37,6 +38,7 @@ public UsageTracker(
3738
IProgram program,
3839
IConnectionManager connectionManager,
3940
IPackageSettings userSettings,
41+
IVSServices vsservices,
4042
[Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
4143
{
4244
fileExists = (path) => System.IO.File.Exists(path);
@@ -46,6 +48,7 @@ public UsageTracker(
4648

4749
this.connectionManager = connectionManager;
4850
this.userSettings = userSettings;
51+
this.vsservices = vsservices;
4952
this.client = serviceProvider.GetExportedValue<IMetricsService>();
5053
this.timer = new DispatcherTimer(
5154
TimeSpan.FromMinutes(1),
@@ -141,7 +144,7 @@ UsageStore LoadUsage()
141144

142145
result.Model.Lang = CultureInfo.InstalledUICulture.IetfLanguageTag;
143146
result.Model.AppVersion = AssemblyVersionInformation.Version;
144-
result.Model.VSVersion = GitHub.VisualStudio.Services.VisualStudioVersion;
147+
result.Model.VSVersion = vsservices.VSVersion;
145148

146149
return result;
147150
}

src/GitHub.Exports/Services/VSServices.cs

+37
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using GitHub.VisualStudio;
77
using Microsoft.VisualStudio;
88
using Microsoft.VisualStudio.Shell.Interop;
9+
using System.Linq;
910

1011
namespace GitHub.Services
1112
{
@@ -21,6 +22,17 @@ public VSServices(IUIProvider serviceProvider)
2122
this.serviceProvider = serviceProvider;
2223
}
2324

25+
string vsVersion;
26+
public string VSVersion
27+
{
28+
get
29+
{
30+
if (vsVersion == null)
31+
vsVersion = GetVSVersion();
32+
return vsVersion;
33+
}
34+
}
35+
2436

2537
public void ActivityLogMessage(string message)
2638
{
@@ -55,5 +67,30 @@ public void ActivityLogWarning(string message)
5567
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Could not log warning to activity log: {0}", message));
5668
}
5769
}
70+
71+
const string RegistryRootKey = @"Software\Microsoft\VisualStudio";
72+
const string EnvVersionKey = "EnvVersion";
73+
string GetVSVersion()
74+
{
75+
var version = VisualStudio.Services.Dte.Version;
76+
var keyPath = String.Format(CultureInfo.InvariantCulture, "{0}\\{1}_Config\\SplashInfo", RegistryRootKey, version);
77+
try
78+
{
79+
using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(keyPath))
80+
{
81+
var value = (string)key.GetValue(EnvVersionKey, String.Empty);
82+
if (!String.IsNullOrEmpty(value))
83+
return value;
84+
}
85+
var asm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName.StartsWith("Microsoft.VisualStudio.CommonIDE", StringComparison.OrdinalIgnoreCase));
86+
if (asm != null)
87+
return asm.GetName().Version.ToString();
88+
}
89+
catch(Exception ex)
90+
{
91+
VsOutputLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, "Error getting the Visual Studio version '{0}'", ex));
92+
}
93+
return version;
94+
}
5895
}
5996
}

0 commit comments

Comments
 (0)