简体   繁体   English

如何使用 C# 确定 Visual Studio 版本

[英]How to determine Visual Studio version with C#

I'm trying to figure out a reliable, future-proof way to determine the installed Visual Studio versions using C#.我正在尝试找出一种可靠的、面向未来的方法来使用 C# 确定已安装的 Visual Studio 版本。

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.但是在我的 PC 上,我发现有几个键名为VisualStudio ,但不属于完整安装。 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.例如,我已经安装了 VS 2019 和 VS Build Tools 2017 - 但在注册表中,我发现14.015.016.016.1等。

Is there any Visual-Studio-API that might could be used?是否有任何可以使用的 Visual-Studio-API?

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");我的问题的深层含义是我必须进行以下调用以支持多个版本的 VS: var developmentToolsEnvironment = (DTE)Marshal.GetActiveObject("VisualStudio.DTE.15.0");

您可以使用 Visual Studio 安装配置 API 来发现 Visual Studio 2017 和更高版本的实例: Visual Studio 安装配置示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM