VSIX - 次要视觉工作室版本 [英] VSIX - Minor visual studio version

查看:30
本文介绍了VSIX - 次要视觉工作室版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道是否/如何从 VSIX 扩展中获取当前正在运行的 Visual Studio 次要版本?

我已经找到了以下属性,但我们想要更详细的版本号(更多部分).

但是由于 VS2017 的安装体验已经针对 vs installer.exe 发生了变化.我们无法再访问该注册表项下有关 VS2017 和 VS2019 的版本详细信息.

对于 VS2017 和 VS2019,我发现我们可以在 HKEY_CURRENT_USER\Software\Microsoft\VSCommon\15.0 或 16.0\SQM\PIDs\ 中访问相关信息.

如果机器上只有一个版本的VS2017和VS2019,可以使用这样的代码获取详细信息:

 DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;字符串版本 = dte.Version;字符串编辑 = dte.Edition;RegistryKey 键 = Registry.CurrentUser;RegistryKey pidsKey = key.OpenSubKey("Software\\Microsoft\\VSCommon\\" + version + "\\SQM\\PIDs\\", true);字符串 [] 实例 = 新字符串 [10];实例 = pidsKey.GetSubKeyNames();RegistryKey instanceKey = key.OpenSubKey("Software\\Microsoft\\VSCommon\\" + version + "\\SQM\\PIDs\\" + instances[0], true);//阅读有关VSManifestID的详细信息string versionInfo = instanceKey.GetValue("VSManifestID").ToString();

versionInfo的格式见这里:VisualStudio/15.9.13+28307.xxx(除了VSManifestID,你也可以使用VSChanelID...)

但是如果您在 PC 上有多个相同 VS 版本的版本(VS20xx 社区和企业在同一台机器上),这将不起作用.在这种情况下,你必须借助dte.Version 和dte.Edition 来添加更多的判断逻辑.

Does somebody know if/how it is possible to obtain the minor Visual Studio version that is currently running, from within a VSIX extension?

I've already found the following property, but we would like to have the more detailed version number (more parts). https://docs.microsoft.com/en-us/dotnet/api/envdte._dte.version?view=visualstudiosdk-2017

解决方案

Assuming you may want the level like X.Y.Z instead of X.0 or X.Y. (e.g: VS2017-15.9.13=>15.9=>15.0).

Sergey's great answer can help you resolve the issue if the format X.Y is enough for you. But if you want to get the full details like VS version+version number, you can consider using registry key.

For VS2015 and earlier versions you can see this vsx document and this similar issue, you can try to use RegistryKey to access the info you want from HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\DevDiv\vs\Servicing\<version>.

But since the installation experience of VS2017 has changed for the vs installer.exe. We can't access the version details about VS2017 and VS2019 under that registry key any more.

For VS2017 and VS2019, I find we can access the related info at HKEY_CURRENT_USER\Software\Microsoft\VSCommon\15.0 or 16.0\SQM\PIDs\.

If in the machine only has one edition of VS2017 and VS2019, you can use code like this to get details:

            DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;
            string version = dte.Version;
            string editon = dte.Edition;

            RegistryKey key = Registry.CurrentUser;
            RegistryKey pidsKey = key.OpenSubKey("Software\\Microsoft\\VSCommon\\" + version + "\\SQM\\PIDs\\", true);
            string[] instances = new string[10];
            instances = pidsKey.GetSubKeyNames();

            RegistryKey instanceKey = key.OpenSubKey("Software\\Microsoft\\VSCommon\\" + version + "\\SQM\\PIDs\\" + instances[0], true);
            //read the details about VSManifestID
            string versionInfo = instanceKey.GetValue("VSManifestID").ToString();

The versionInfo's format see here: VisualStudio/15.9.13+28307.xxx (Apart from VSManifestID, you can also use VSChanelID...)

But this won't work if you have more than one edition of same VS version in PC.(VS20xx community and enterprise in same machine). In this situation you have to add much more judgement logic with the help of dte.Version and dte.Edition.

这篇关于VSIX - 次要视觉工作室版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆