2

I'm trying to figure out a reliable, future-proof way to determine the installed Visual Studio versions using C#.

My first idea was to use the registry. But on my PC, I found several keys being named VisualStudio, but not belonging to a complete installation. For example, I've installed VS 2019 and VS Build Tools 2017 - but within the registry, I'm finding 14.0, 15.0, 16.0, 16.1, etc.

Is there any Visual-Studio-API that might could be used?

The deeper meaning of my question is that I have to make the following call supporting multiple versions of VS: var developmentToolsEnvironment = (DTE)Marshal.GetActiveObject("VisualStudio.DTE.15.0");

mu88
  • 4,156
  • 1
  • 23
  • 47
  • 1
    You could maybe just try different values in `Type.GetTypeFromProgID("VisualStudio.DTE.x.0")` and see what isn't null – stuartd Jul 23 '19 at 12:12
  • That's right, but honestly, I thought of avoiding trial and error – mu88 Jul 23 '19 at 12:15
  • Check for version-specific folders on the disks – BWA Jul 23 '19 at 12:18
  • 1
    You could check the list of installed programs. https://stackoverflow.com/questions/908850/get-installed-applications-in-a-system –  Jul 23 '19 at 12:37
  • @BWA Not only it could lead to false info (some uninstallers failt to remove all the data) but Visual Studio has different folder structures depending on the version used. I would go registry. – Cleptus Jul 23 '19 at 12:43
  • What do you think of using `HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall`? Should this be safe enough? – mu88 Jul 23 '19 at 12:45
  • Have a look at this... https://stackoverflow.com/questions/5089389/how-can-i-check-what-version-edition-of-visual-studio-is-installed-programmatica – Reinstate Monica Cellio Jul 23 '19 at 13:02

1 Answers1

1

You can use Visual Studio setup configuration API for discovering instances of Visual Studio 2017 and newer: Visual Studio Setup Configuration Samples.

Sergey Vlasov
  • 26,641
  • 3
  • 64
  • 66