diff --git a/src/BenchmarkDotNet/BenchmarkDotNet.csproj b/src/BenchmarkDotNet/BenchmarkDotNet.csproj
index 7bd9e11155..41688288b2 100644
--- a/src/BenchmarkDotNet/BenchmarkDotNet.csproj
+++ b/src/BenchmarkDotNet/BenchmarkDotNet.csproj
@@ -58,4 +58,14 @@
+
+
+ true
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
diff --git a/src/BenchmarkDotNet/Detectors/Cpu/Windows/MosCpuDetector.cs b/src/BenchmarkDotNet/Detectors/Cpu/Windows/MosCpuDetector.cs
index edc48ba25d..3f75a8122a 100644
--- a/src/BenchmarkDotNet/Detectors/Cpu/Windows/MosCpuDetector.cs
+++ b/src/BenchmarkDotNet/Detectors/Cpu/Windows/MosCpuDetector.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Management;
+using System.Runtime.Versioning;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Portability;
using Perfolizer.Horology;
@@ -11,16 +12,12 @@ namespace BenchmarkDotNet.Detectors.Cpu.Windows;
internal class MosCpuDetector : ICpuDetector
{
-#if NET6_0_OR_GREATER
- [System.Runtime.Versioning.SupportedOSPlatform("windows")]
-#endif
+ [SupportedOSPlatform("windows")]
public bool IsApplicable() => OsDetector.IsWindows() &&
RuntimeInformation.IsFullFramework &&
!RuntimeInformation.IsMono;
-#if NET6_0_OR_GREATER
- [System.Runtime.Versioning.SupportedOSPlatform("windows")]
-#endif
+ [SupportedOSPlatform("windows")]
public CpuInfo? Detect()
{
if (!IsApplicable()) return null;
diff --git a/src/BenchmarkDotNet/Detectors/Cpu/Windows/PowershellWmiCpuDetector.cs b/src/BenchmarkDotNet/Detectors/Cpu/Windows/PowershellWmiCpuDetector.cs
index 7f61c1b8fc..480abd2dee 100644
--- a/src/BenchmarkDotNet/Detectors/Cpu/Windows/PowershellWmiCpuDetector.cs
+++ b/src/BenchmarkDotNet/Detectors/Cpu/Windows/PowershellWmiCpuDetector.cs
@@ -21,9 +21,7 @@ internal class PowershellWmiCpuDetector : ICpuDetector
public bool IsApplicable() => OsDetector.IsWindows();
- #if NET6_0_OR_GREATER
[SupportedOSPlatform("windows")]
- #endif
public CpuInfo? Detect()
{
if (!IsApplicable()) return null;
diff --git a/src/BenchmarkDotNet/Detectors/OsDetector.cs b/src/BenchmarkDotNet/Detectors/OsDetector.cs
index 5deeea03a6..615a9e3550 100644
--- a/src/BenchmarkDotNet/Detectors/OsDetector.cs
+++ b/src/BenchmarkDotNet/Detectors/OsDetector.cs
@@ -8,6 +8,7 @@
using Perfolizer.Models;
using static System.Runtime.InteropServices.RuntimeInformation;
using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;
+using System.Runtime.Versioning;
namespace BenchmarkDotNet.Detectors;
@@ -113,9 +114,7 @@ private static bool IsUnderWsl()
return null;
}
-#if NET6_0_OR_GREATER
- [System.Runtime.Versioning.SupportedOSPlatformGuard("windows")]
-#endif
+ [SupportedOSPlatformGuard("windows")]
internal static bool IsWindows() =>
#if NET6_0_OR_GREATER
OperatingSystem.IsWindows(); // prefer linker-friendly OperatingSystem APIs
@@ -123,9 +122,8 @@ internal static bool IsWindows() =>
IsOSPlatform(OSPlatform.Windows);
#endif
-#if NET6_0_OR_GREATER
- [System.Runtime.Versioning.SupportedOSPlatformGuard("linux")]
-#endif
+
+ [SupportedOSPlatformGuard("linux")]
internal static bool IsLinux() =>
#if NET6_0_OR_GREATER
OperatingSystem.IsLinux();
@@ -133,9 +131,7 @@ internal static bool IsLinux() =>
IsOSPlatform(OSPlatform.Linux);
#endif
-#if NET6_0_OR_GREATER
- [System.Runtime.Versioning.SupportedOSPlatformGuard("macos")]
-#endif
+ [SupportedOSPlatformGuard("macos")]
// ReSharper disable once InconsistentNaming
internal static bool IsMacOS() =>
#if NET6_0_OR_GREATER
@@ -144,9 +140,7 @@ internal static bool IsMacOS() =>
IsOSPlatform(OSPlatform.OSX);
#endif
-#if NET6_0_OR_GREATER
- [System.Runtime.Versioning.SupportedOSPlatformGuard("android")]
-#endif
+ [SupportedOSPlatformGuard("android")]
internal static bool IsAndroid() =>
#if NET6_0_OR_GREATER
OperatingSystem.IsAndroid();
@@ -154,9 +148,7 @@ internal static bool IsAndroid() =>
Type.GetType("Java.Lang.Object, Mono.Android") != null;
#endif
-#if NET6_0_OR_GREATER
- [System.Runtime.Versioning.SupportedOSPlatformGuard("ios")]
-#endif
+ [SupportedOSPlatformGuard("ios")]
// ReSharper disable once InconsistentNaming
internal static bool IsIOS() =>
#if NET6_0_OR_GREATER
@@ -165,9 +157,7 @@ internal static bool IsIOS() =>
Type.GetType("Foundation.NSObject, Xamarin.iOS") != null;
#endif
-#if NET6_0_OR_GREATER
- [System.Runtime.Versioning.SupportedOSPlatformGuard("tvos")]
-#endif
+ [SupportedOSPlatformGuard("tvos")]
// ReSharper disable once InconsistentNaming
internal static bool IsTvOS() =>
#if NET6_0_OR_GREATER
diff --git a/src/BenchmarkDotNet/Helpers/FrameworkVersionHelper.cs b/src/BenchmarkDotNet/Helpers/FrameworkVersionHelper.cs
index 7c87f0c561..09558d4d74 100644
--- a/src/BenchmarkDotNet/Helpers/FrameworkVersionHelper.cs
+++ b/src/BenchmarkDotNet/Helpers/FrameworkVersionHelper.cs
@@ -83,10 +83,7 @@ internal static string MapToReleaseVersion(string servicingVersion)
return "4.8.1"; // most probably the last major release of Full .NET Framework
}
-
-#if NET6_0_OR_GREATER
[SupportedOSPlatform("windows")]
-#endif
private static int? GetReleaseNumberFromWindowsRegistry()
{
using var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
@@ -96,9 +93,7 @@ internal static string MapToReleaseVersion(string servicingVersion)
return Convert.ToInt32(ndpKey.GetValue("Release"));
}
-#if NET6_0_OR_GREATER
[SupportedOSPlatform("windows")]
-#endif
internal static string? GetLatestNetDeveloperPackVersion()
{
if (GetReleaseNumberFromWindowsRegistry() is not int releaseNumber)
diff --git a/src/BenchmarkDotNet/Helpers/PowerShellLocator.cs b/src/BenchmarkDotNet/Helpers/PowerShellLocator.cs
index 28b8e910f7..0c092e467d 100644
--- a/src/BenchmarkDotNet/Helpers/PowerShellLocator.cs
+++ b/src/BenchmarkDotNet/Helpers/PowerShellLocator.cs
@@ -16,9 +16,7 @@ internal class PowerShellLocator
$"{Environment.SystemDirectory}{Path.DirectorySeparatorChar}WindowsPowerShell{Path.DirectorySeparatorChar}" +
$"v1.0{Path.DirectorySeparatorChar}powershell.exe";
-#if NET6_0_OR_GREATER
[SupportedOSPlatform("windows")]
-#endif
internal static string? LocateOnWindows()
{
if (OsDetector.IsWindows() == false)
diff --git a/src/BenchmarkDotNet/Portability/RuntimeInformation.cs b/src/BenchmarkDotNet/Portability/RuntimeInformation.cs
index 530c4dd8a4..dfbb958fa2 100644
--- a/src/BenchmarkDotNet/Portability/RuntimeInformation.cs
+++ b/src/BenchmarkDotNet/Portability/RuntimeInformation.cs
@@ -6,6 +6,7 @@
using System.Management;
using System.Reflection;
using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BenchmarkDotNet.Detectors;
using BenchmarkDotNet.Environments;
@@ -42,8 +43,8 @@ internal static class RuntimeInformation
FrameworkDescription.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase);
#endif
+ [SupportedOSPlatformGuard("browser")]
#if NET6_0_OR_GREATER
- [System.Runtime.Versioning.SupportedOSPlatformGuard("browser")]
public static readonly bool IsWasm = OperatingSystem.IsBrowser();
#else
public static readonly bool IsWasm = IsOSPlatform(OSPlatform.Create("BROWSER"));
diff --git a/src/BenchmarkDotNet/Running/ConsoleTitler.cs b/src/BenchmarkDotNet/Running/ConsoleTitler.cs
index d045e498aa..e95eb590c4 100644
--- a/src/BenchmarkDotNet/Running/ConsoleTitler.cs
+++ b/src/BenchmarkDotNet/Running/ConsoleTitler.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.Runtime.Versioning;
using BenchmarkDotNet.Detectors;
using BenchmarkDotNet.Helpers;
@@ -60,9 +61,7 @@ public ConsoleTitler(string initialTitle)
}
}
-#if NET6_0_OR_GREATER
- [System.Runtime.Versioning.SupportedOSPlatformGuard("windows")]
-#endif
+ [SupportedOSPlatformGuard("windows")]
private static bool PlatformSupportsTitleRead() => OsDetector.IsWindows();
///
diff --git a/src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/InProcessNoEmitRunner.cs b/src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/InProcessNoEmitRunner.cs
index 18ee40c30a..491ed35591 100644
--- a/src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/InProcessNoEmitRunner.cs
+++ b/src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/InProcessNoEmitRunner.cs
@@ -16,9 +16,7 @@ namespace BenchmarkDotNet.Toolchains.InProcess.NoEmit
///
internal class InProcessNoEmitRunner
{
-#if NET6_0_OR_GREATER
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Runnable))]
-#endif
public static int Run(IHost host, BenchmarkCase benchmarkCase)
{
// the first thing to do is to let diagnosers hook in before anything happens
diff --git a/tests/BenchmarkDotNet.IntegrationTests/WakeLockTests.cs b/tests/BenchmarkDotNet.IntegrationTests/WakeLockTests.cs
index cf8d0d39b9..968c5697b6 100644
--- a/tests/BenchmarkDotNet.IntegrationTests/WakeLockTests.cs
+++ b/tests/BenchmarkDotNet.IntegrationTests/WakeLockTests.cs
@@ -85,9 +85,7 @@ public class IgnoreWakeLock
[Benchmark] public void Sleep() { }
}
-#if !NET462
[SupportedOSPlatform("windows")]
-#endif
[TheoryEnvSpecific(EnvRequirement.WindowsOnly, EnvRequirement.NeedsPrivilegedProcess)]
[InlineData(typeof(Default), "SYSTEM")]
[InlineData(typeof(None), "")]
@@ -124,9 +122,7 @@ public class Default : Base { }
public class Base
{
[Benchmark]
-#if !NET462
[SupportedOSPlatform("windows")]
-#endif
public void SignalBenchmarkRunningAndWaitForGetPowerRequests()
{
using EventWaitHandle