示例#1
0
        public async Task <Version?> GetVSVersionAsync(ProjectSystem.VS.IVsService <IVsAppId> vsAppIdService)
        {
            await _threadingService.SwitchToUIThread();

            IVsAppId vsAppId = await vsAppIdService.GetValueAsync();

            if (ErrorHandler.Succeeded(vsAppId.GetProperty((int)VSAPropID.VSAPROPID_ProductSemanticVersion, out object oVersion)) &&
                oVersion is string semVersion)
            {
                // This is a semantic version string. We only care about the non-semantic version part
                int index = semVersion.IndexOfAny(Delimiter.PlusAndMinus);
                if (index != -1)
                {
                    semVersion = semVersion.Substring(0, index);
                }

                if (Version.TryParse(semVersion, out Version vsVersion))
                {
                    return(vsVersion);
                }
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// <see cref="IVsShellUtilitiesHelper.GetVSVersionAsync"/>
        /// </summary>
        public async Task <Version> GetVSVersionAsync(IServiceProvider serviceProvider)
        {
            await _threadingService.SwitchToUIThread();

            IVsAppId vsAppId = serviceProvider.GetService <IVsAppId, SVsAppId>();

            if (ErrorHandler.Succeeded(vsAppId.GetProperty((int)VSAPropID.VSAPROPID_ProductSemanticVersion, out object oVersion)) &&
                oVersion is string semVersion)
            {
                // This is a semantic version string. We only care about the non-semantic version part
                int index = semVersion.IndexOfAny(new char[] { '-', '+' });
                if (index != -1)
                {
                    semVersion = semVersion.Substring(0, index);
                }

                if (Version.TryParse(semVersion, out Version vsVersion))
                {
                    return(vsVersion);
                }
            }

            return(null);
        }
示例#3
0
 internal static T GetProperty <T>(this IVsAppId vsAppId, VSAPropID propid)
 {
     if (vsAppId != null && ErrorHandler.Succeeded(vsAppId.GetProperty((int)propid, out var prop)))
     {
         return((T)prop);
     }