Skip to content

Instantly share code, notes, and snippets.

@shana
Created January 24, 2018 14:32
Show Gist options
  • Save shana/110dbe51dd6e08c652f3b9b8cba3cd7b to your computer and use it in GitHub Desktop.
Save shana/110dbe51dd6e08c652f3b9b8cba3cd7b to your computer and use it in GitHub Desktop.
getting the stupid version of vs 2017
var devenv = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
// C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances
var pathToInstallationData = Path.Combine(os.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData),
"Microsoft", "VisualStudio", "Packages", "_Instances");
var regexVersion = new Regex(@"""productDisplayVersion"":""([^""]+)""");
var regexPath = new Regex(@"""installationPath"":""([^""]+)""");
foreach (var dir in os.Directory.EnumerateDirectories(pathToInstallationData))
{
var data = os.File.ReadAllText(Path.Combine(dir, "state.json"), System.Text.Encoding.UTF8);
if (regexPath.IsMatch(data) && regexVersion.IsMatch(data))
{
var path = regexPath.Match(data).Groups[1].Value;
path = path.Replace("\\\\", "\\");
if (devenv.StartsWith(path, StringComparison.OrdinalIgnoreCase))
{
version = regexVersion.Match(data).Groups[1].Value;
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment