Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#2738) Check installed .NET version installed is at least 4.8 #2935

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/chocolatey.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -124,6 +126,8 @@ private static void Main(string[] args)
}
}

check_installed_dotnetfx_version();
gep13 marked this conversation as resolved.
Show resolved Hide resolved

if (warnings.Count != 0 && config.RegularOutput)
{
foreach (var warning in warnings.or_empty_list_if_null())
Expand Down Expand Up @@ -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)
gep13 marked this conversation as resolved.
Show resolved Hide resolved
{
// https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#minimum-version
const int NET48RELEASEBUILD = 528040;
TheCakeIsNaOH marked this conversation as resolved.
Show resolved Hide resolved
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));
}
}
}
}
}
}