nunit-console icon indicating copy to clipboard operation
nunit-console copied to clipboard

Add Guard statements for OS-specific APIs

Open CharliePoole opened this issue 3 years ago • 1 comments

This is a soft prerequisite to #1044. That is, we could work around it in somewhat complicated ways... but let's not!

Our .NET 5.0 builds contain unguarded calls to Windows-specific apis like Registry.GetRegistryKey. They work because we don't actually call those APIs unless we have verified that we are running on Windows.

Once we introduce .NET 6.0 builds, the default settings will result in errors for those calls. While we could suppress those checks, it makes more sense to go ahead and start using guard statements like if (OperatingSystem.IsWindows()) before such calls.

In addition, we should probably isolate such code in separate methods and apply SupportedOSPlatformAttribute to them.

CharliePoole avatar Jan 25 '22 13:01 CharliePoole

After fixing #1115, my test build using net6.0 no longer gives errors due to windows-specific apis, so I'm removing this from the 3.15.0 milestone.

We'll still need to look at this issue for 4.0.

CharliePoole avatar Jan 26 '22 19:01 CharliePoole