To get the full semantic version that includes the patch numbers, like "15.9.6", neither DTE.Version
nor the file versions give sufficient information.
I have found a solution in the new managed project system (https://github.com/dotnet/project-system) that seems to be working in VS2017 at least.
Basically, it is using the IVsAppId
COM interface, that you need to declare, like in this file. (You can basically copy that file as it is.)
Once you did that, you need to get the IVsAppId
implementation in the usual way through a service provider, and call the GetProperty
method with VSAPropID.VSAPROPID_ProductSemanticVersion
(the enum is also defined in the linked file):
var vsAppId = serviceProvider.GetService<IVsAppId>(typeof(SVsAppId));
vsAppId.GetProperty((int)VSAPropID.VSAPROPID_ProductSemanticVersion, out var semanticVersionObj);
The semanticVersionObj
in the sample above will contain a string, in format, like 15.9.6+28307.344
. Getting the part before +
(sometimes -
) gives you the semantic version: 15.9.6
.
BTW: it is used in the managed project system here.
(It is so great that MS made the new project system code open source. It provides a good source of information and also you can find useful patterns in it.)