-
Notifications
You must be signed in to change notification settings - Fork 24
/
VersionInfo.cs
138 lines (122 loc) · 5.04 KB
/
VersionInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
namespace BIDSHelper.Core
{
public class VersionInfo
{
// BIDS Helper Assembly & VSIX Version
// N.B. Manually update the manifest file, if you change this - See source.extension.vsixmanifest
public const string Version = "2.0.1";
private static readonly object lockResource = new object();
private static Version visualStudioVersion;
private static Version sqlServerVersion;
// Adapted from http://stackoverflow.com/questions/11082436/detect-the-visual-studio-version-inside-a-vspackage
public static Version VisualStudioVersion
{
get
{
lock (lockResource)
{
if (visualStudioVersion == null)
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "msenv.dll");
if (File.Exists(path))
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(path);
string verName = fvi.ProductVersion;
for (int i = 0; i < verName.Length; i++)
{
if (!char.IsDigit(verName, i) && verName[i] != '.')
{
verName = verName.Substring(0, i);
break;
}
}
visualStudioVersion = new Version(verName);
}
else
{
visualStudioVersion = new Version(0, 0); // Not running inside Visual Studio!
}
}
}
return visualStudioVersion;
}
}
public static string VisualStudioFriendlyVersion
{
get
{
switch (VisualStudioVersion.Major)
{
case 8:
return "2005";
case 9:
return "2008";
case 10:
return "2010";
case 11:
return "2012";
case 12:
return "2013";
case 14:
return "2015";
case 15:
return "\"15\""; // Unofficial
default:
return string.Format("(VS Unknown {0})", VisualStudioVersion.ToString());
}
}
}
public static Version SqlServerVersion
{
get
{
lock (lockResource)
{
if (sqlServerVersion == null)
{
//TODO: maybe read the proper SSDT version number from the registry here? HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0_Config\InstalledProducts\Microsoft SQL Server Data Tools
// Get a sample assembly that's installed with BIDS and use that to detect if BIDS is installed
Assembly assembly = Assembly.Load("Microsoft.DataWarehouse");
AssemblyInformationalVersionAttribute attributeVersion = (AssemblyInformationalVersionAttribute)Attribute.GetCustomAttribute(assembly, typeof(AssemblyInformationalVersionAttribute));
if (attributeVersion != null)
{
sqlServerVersion = new Version(attributeVersion.InformationalVersion);
}
else
{
sqlServerVersion = assembly.GetName().Version;
}
}
return sqlServerVersion;
}
}
}
public static string SqlServerFriendlyVersion
{
get
{
string sVersion = SqlServerVersion.ToString();
if (sVersion.StartsWith("9."))
return "2005";
else if (sVersion.StartsWith("10.5"))
return "2008 R2";
else if (sVersion.StartsWith("10."))
return "2008";
else if (sVersion.StartsWith("11."))
return "2012";
else if (sVersion.StartsWith("12."))
return "2014";
else if (sVersion.StartsWith("13."))
return "2016";
else if (sVersion.StartsWith("14."))
return "2017";
else
return string.Format("(SQL Unknown {0})", sVersion);
}
}
}
}