Skip to content

Commit

Permalink
(#2738) Check installed .NET version installed is at least 4.8
Browse files Browse the repository at this point in the history
This adds a registry check to chocolatey.console to validate that .Net
4.8 or later is installed. This check is added because Chocolatey CLI
can start to execute but runs into errors when the system has an older
version of .Net framework installed. The check is very early on in the
execution so as to print out a helpful error before any errors due to
incompatibilities with the older .Net version show up.
  • Loading branch information
TheCakeIsNaOH committed Dec 14, 2022
1 parent 677389a commit dff4453
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/chocolatey.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace chocolatey.console
using Console = System.Console;
using Environment = System.Environment;
using IFileSystem = infrastructure.filesystem.IFileSystem;
using Microsoft.Win32;
using chocolatey.infrastructure.platforms;

public sealed class Program
{
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -370,5 +374,24 @@ 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)
{
const string REGKEY = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
const int NET48RELEASEBUILD = 528040;

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{0}Install .NET 4.8 and reboot the system"
.format_with(Environment.NewLine));
}
}
}
}
}
}

0 comments on commit dff4453

Please sign in to comment.