Skip to content

Commit eb95714

Browse files
committed
(#3228) Throw earlier if .Net 4.8 is not present
There are instances where .Net is not installed in a way that allows Chocolatey CLI to function. In these scenarios, the version in the registry seems to be very old. This commit moves the test for .Net 4.8 earlier in program execution in order to provide a more user friendly error message. Additionally, this changes the check to use Registry64 instead of Registry32, as on 64 bit systems the 64 bit registry is the one that determines the .Net version. And the lookup on 32 bit systems gracefully falls back to the 32 bit registry.
1 parent 6d82bc0 commit eb95714

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/chocolatey.console/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ private static void Main(string[] args)
6969
Bootstrap.Initialize();
7070
Bootstrap.Startup();
7171
license = License.ValidateLicense();
72+
ThrowIfNotDotNet48();
7273
var container = SimpleInjectorContainer.Container;
7374

7475
"LogFileOnly".Log().Info(() => "".PadRight(60, '='));
@@ -125,8 +126,6 @@ private static void Main(string[] args)
125126
}
126127
}
127128

128-
ThrowIfNotDotNet48();
129-
130129
if (warnings.Count != 0 && config.RegularOutput)
131130
{
132131
foreach (var warning in warnings.OrEmpty())
@@ -328,15 +327,16 @@ private static void ThrowIfNotDotNet48()
328327
const int net48ReleaseBuild = 528040;
329328
const string regKey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
330329

331-
using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(regKey))
330+
// Use 64 bit hive as it will read the 32 bit hive on 32 bit system: https://learn.microsoft.com/en-us/dotnet/api/microsoft.win32.registryview
331+
using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(regKey))
332332
{
333333
if (ndpKey == null || ndpKey.GetValue("Release") == null || (int)ndpKey.GetValue("Release") < net48ReleaseBuild)
334334
{
335335
throw new ApplicationException(
336336
@".NET 4.8 is not installed or may need a reboot to complete installation.
337337
Please install .NET Framework 4.8 manually and reboot the system.
338338
Download at 'https://download.visualstudio.microsoft.com/download/pr/2d6bb6b2-226a-4baa-bdec-798822606ff1/8494001c276a4b96804cde7829c04d7f/ndp48-x86-x64-allos-enu.exe'"
339-
.FormatWith(Environment.NewLine));
339+
);
340340
}
341341
}
342342
}

0 commit comments

Comments
 (0)