Skip to content

Instantly share code, notes, and snippets.

@GoEddie
Created May 4, 2017 20:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GoEddie/7dcf10fb8d0ac2e72c35a25a195e3a7b to your computer and use it in GitHub Desktop.
Save GoEddie/7dcf10fb8d0ac2e72c35a25a195e3a7b to your computer and use it in GitHub Desktop.
If you have an SSDT project in visual studio and want to get the version of sql it is targetting because everything is internal :( do this!
string GetTargetSqlServerVersion(){
var dte = (DTE)GetService(typeof(DTE));
var project = dte.ActiveDocument.ProjectItem.ContainingProject;
return project.GetType().GetProperty("Globals").GetValue(project).GetType().GetProperty("Parent").GetValue(project.GetType().GetProperty("Globals").GetValue(project)).GetType().GetProperty("DatabaseSchemaProvider").GetValue(project.GetType().GetProperty("Globals").GetValue(project).GetType().GetProperty("Parent").GetValue(project.GetType().GetProperty("Globals").GetValue(project))).GetType().GetProperty("Platform").GetValue(project.GetType().GetProperty("Globals").GetValue(project).GetType().GetProperty("Parent").GetValue(project.GetType().GetProperty("Globals").GetValue(project)).GetType().GetProperty("DatabaseSchemaProvider").GetValue(project.GetType().GetProperty("Globals").GetValue(project).GetType().GetProperty("Parent").GetValue(project.GetType().GetProperty("Globals").GetValue(project))))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment