diff --git a/src/chocolatey.console/Program.cs b/src/chocolatey.console/Program.cs index 97cefd3b45..24805f9aad 100644 --- a/src/chocolatey.console/Program.cs +++ b/src/chocolatey.console/Program.cs @@ -21,6 +21,7 @@ namespace chocolatey.console using System.IO; using System.Linq; using System.Reflection; + using Microsoft.Win32; using chocolatey.infrastructure.information; using infrastructure.app; using infrastructure.app.builders; @@ -30,6 +31,7 @@ namespace chocolatey.console using infrastructure.extractors; using infrastructure.licensing; using infrastructure.logging; + using infrastructure.platforms; using infrastructure.registration; using infrastructure.tolerance; using SimpleInjector; @@ -124,6 +126,8 @@ private static void Main(string[] args) } } + check_installed_dotnetfx_version(); + if (warnings.Count != 0 && config.RegularOutput) { foreach (var warning in warnings.or_empty_list_if_null()) @@ -297,5 +301,27 @@ you can ignore this warning. Or by passing the --skip-compatibility-checks option when executing a command."); } + + private static void check_installed_dotnetfx_version() + { + if (Platform.get_platform() == PlatformType.Windows) + { + // https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#minimum-version + const int NET48RELEASEBUILD = 528040; + const string REGKEY = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"; + + using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(REGKEY)) + { + if (ndpKey == null || ndpKey.GetValue("Release") == null || (int)ndpKey.GetValue("Release") < NET48RELEASEBUILD) + { + throw new ApplicationException( + @".NET 4.8 is not installed or may need a reboot to complete installation. +Please install .NET Framework 4.8 manually and reboot the system. +Download at 'https://download.visualstudio.microsoft.com/download/pr/2d6bb6b2-226a-4baa-bdec-798822606ff1/8494001c276a4b96804cde7829c04d7f/ndp48-x86-x64-allos-enu.exe'" + .format_with(Environment.NewLine)); + } + } + } + } } }