All right all I am stuck, and I think I need some help. I have multiple versions of Visual Studio Installed. When launching the app, I want it to be able to find all the visual studio versions, return them, so the user can select what version they want to use. In earlier versions, you could do this with the path and the registry key to check what versions that are installed.
Now VS17 is more lightweight and is installed differently so you cannot use the registry key anymore. I am looking at https://code.msdn.microsoft.com/windowsdesktop/Visual-Studio-Setup-0cedd331#content, and https://github.com/Microsoft/vswhere but I cannot seem to get them to work.
The idea is that the user would click the solutions file in the internal application and we would launch the latest version of Visual Studio.
Here is a snippet of how the current code works to find previous versions:
private class VsVersion
{
public static VsVersion TryResolveInstalledVersion()
{
// Note: Newest version first
// Note: This search will fail on 32-bit systems
var versions = new[] {
new {
ExecutablePath = @"%PROGRAMFILES(x86)%\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe",
RegistrySubKey = @"Software\Microsoft\VisualStudio\14.0"
},
new {
ExecutablePath = @"%PROGRAMFILES(x86)%\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe",
RegistrySubKey = @"Software\Microsoft\VisualStudio\12.0"
},
new {
ExecutablePath = @"%PROGRAMFILES(x86)%\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe",
RegistrySubKey = @"Software\Microsoft\VisualStudio\11.0"
}
};
foreach (var version in versions)
{
var executablePath = Environment.ExpandEnvironmentVariables(version.ExecutablePath);
if (File.Exists(executablePath))
{
return new VsVersion(executablePath, version.RegistrySubKey);
}
}
return null;
}
private VsVersion(string executablePath, string registrySubKey)
{
ExecutablePath = executablePath;
RegistrySubKey = registrySubKey;
}
public string ExecutablePath { get; }
public string RegistrySubKey { get; }
}