当前位置:网站首页>C# Get system installed .NET version

C# Get system installed .NET version

2022-08-09 11:45:00 yanjinhua

本文经原作者授权以原创方式二次分享,欢迎转载、分享.

原文作者:唐宋元明清

原文地址: https://www.cnblogs.com/kybs0/p/16478587.html

C# Get system installed.NET版本

Get system installed.NET版本,to determine the environment in which the current application can run.

Get system installed.NET版本

Microsoft already has the corresponding full documentation,请参考:确定已安装的 .NET Framework 版本 - .NET Framework | Microsoft Docs

  • ReleaseAccording to the documentation it is the version key,Should be a similar version build number,Can determine whether it is installed.NET.

  • Version是.NetFramework的版本

  • I sorted it outVersion的方法,方便大家获取:

private Version GetFrameworkVersion()
    {
        string registerKey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
        var defaultVersion = new Version(00);
        try
        {
            using (var sub = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(registerKey))
            {
                if (!(sub?.GetValue("Release"is int key))
                    return defaultVersion;

                //判断
                if (key >= 528040)
                    return new Version(48);
                if (key >= 461808)
                    return new Version(472);
                if (key >= 461308)
                    return new Version(471);
                if (key >= 460798)
                    return new Version(47);
                if (key >= 394802)
                    return new Version(462);
                if (key >= 394254)
                    return new Version(461);
                if (key >= 393295)
                    return new Version(46);
                if (key >= 379893)
                    return new Version(452);
                if (key >= 378675)
                    return new Version(451);
                if (key >= 378389)
                    return new Version(45);
            }
        }
        catch (Exception)
        {
            // ignored
        }
        //小于4.5,This environment generally does not exist
        return new Version(00);
    }
  • 注:Get a computer quickly if you need it. NET版本,可以通过 PowerShell查看
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client' -Name Version).Version
原网站

版权声明
本文为[yanjinhua]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091131168008.html