From 8d746fb782e6e028ef191e88acb8db2c6be3503d Mon Sep 17 00:00:00 2001 From: Matt Richardson Date: Mon, 15 Jun 2026 15:18:56 +1000 Subject: [PATCH] Fix CA1416: mark IsRunningOnWindows as a platform guard Annotate CalamariEnvironment.IsRunningOnWindows with [SupportedOSPlatformGuard("windows")] so the platform-compatibility analyzer recognises it as an OS guard. CA1416 only understands the BCL guards (OperatingSystem.IsWindows() etc.), so it couldn't tell that guarded call sites (e.g. File.Get/SetUnixFileMode in DockerCredentialHelper) are unreachable on Windows. The attribute is read from metadata, so this works cross-assembly and clears the warning anywhere the property is used as a guard, without changing the property's behaviour. Co-Authored-By: Claude Opus 4.8 (1M context) --- source/Calamari.Common/Plumbing/CalamariEnvironment.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/Calamari.Common/Plumbing/CalamariEnvironment.cs b/source/Calamari.Common/Plumbing/CalamariEnvironment.cs index bd8ee938c7..9b62fa0539 100644 --- a/source/Calamari.Common/Plumbing/CalamariEnvironment.cs +++ b/source/Calamari.Common/Plumbing/CalamariEnvironment.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using Calamari.Common.Plumbing.Variables; namespace Calamari.Common.Plumbing @@ -15,6 +16,7 @@ public static class CalamariEnvironment /// public static bool IsRunningOnNix => Environment.OSVersion.Platform == PlatformID.Unix && !IsRunningOnMac; + [SupportedOSPlatformGuard("windows")] public static bool IsRunningOnWindows => Environment.OSVersion.Platform == PlatformID.Win32NT || Environment.OSVersion.Platform == PlatformID.Win32S || Environment.OSVersion.Platform == PlatformID.Win32Windows ||