简体   繁体   中英

VSIX - Minor visual studio version

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

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());

Assuming you may want the level like XYZ instead of X.0 or XY . (eg: VS2017-15.9.13=>15.9=>15.0).

Sergey's great answer can help you resolve the issue if the format XY 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 .

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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