VSIX - Minor visual studio version

佐手、 提交于 2020-06-13 09:09:08

问题


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


回答1:


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.




回答2:


The following code shows "16.0.29306.81 D16.2" in my VS 2019:

var shell = (package as System.IServiceProvider).GetService(typeof(Microsoft.VisualStudio.Shell.Interop.SVsShell)) as Microsoft.VisualStudio.Shell.Interop.IVsShell;
object ver = null;
shell.GetProperty((int)Microsoft.VisualStudio.Shell.Interop.__VSSPROPID5.VSSPROPID_ReleaseVersion, out ver);
System.Windows.MessageBox.Show(ver.ToString());



回答3:


The easiest way to find the minor part of VS is to get version information from the file "devenv.exe":

var devenvInfo = FileVersionInfo.GetVersionInfo(dte.FullName);
return new Version(devenvInfo.FileMajorPart, devenvInfo.FileMinorPart);


来源:https://stackoverflow.com/questions/57867761/vsix-minor-visual-studio-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!