Created
January 24, 2018 14:32
-
-
Save shana/110dbe51dd6e08c652f3b9b8cba3cd7b to your computer and use it in GitHub Desktop.
getting the stupid version of vs 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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