Skip to content

Commit 762b76c

Browse files
Cleanup dependencies and add net6.0 TFM (#2012)
* Ignore local BenchmarkDotNet.Disassembler packages Ignore any BenchmarkDotNet.Disassembler NuGet packages created during a local build. * Clean up dependencies Clean up the package dependencies as described in #2009. * Add net6.0 TFM - Add a net6.0 TFM. - Resolve supported platform and obsolete warnings for .NET 6. * Add TODO for .NET Framework 4.8.1 Add a TODO to correctly return the version for .NET Framework 4.8.1. * Suppress analyser diagnostics - Suppress IDE0052 warning in Visual Studio. - Suppress IDE0079 warning for redundant ReSharper warning in Visual Studio. * Update Microsoft.CodeAnalysis.CSharp Update Microsoft.CodeAnalysis.CSharp to 3.0.0 to use a version that targets netstandard2.0. * Make IsFullFramework always false for net6.0 .NET 6 is not .NET Framework by definition. * Use PlatformApis instead of Environment.OS* See #2012 (comment).
1 parent 23f9958 commit 762b76c

18 files changed

+412
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ artifacts/*
4949
BDN.Generated
5050
BenchmarkDotNet.Samples/Properties/launchSettings.json
5151
src/BenchmarkDotNet/Disassemblers/net461/*
52+
src/BenchmarkDotNet/Disassemblers/BenchmarkDotNet.Disassembler.*.nupkg
5253

5354
# Visual Studio 2015 cache/options directory
5455
.vs/

src/BenchmarkDotNet/BenchmarkDotNet.csproj

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="..\..\build\common.props" />
33
<PropertyGroup>
44
<AssemblyTitle>BenchmarkDotNet</AssemblyTitle>
5-
<TargetFramework>netstandard2.0</TargetFramework>
5+
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
<NoWarn>$(NoWarn);1701;1702;1705;1591;3005;NU1702;CS3001;CS3003</NoWarn>
88
<AssemblyName>BenchmarkDotNet</AssemblyName>
@@ -17,18 +17,19 @@
1717
<PackageReference Include="CommandLineParser" Version="2.4.3" />
1818
<PackageReference Include="Iced" Version="1.17.0" />
1919
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="1.1.126102" />
20-
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />
21-
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
2220
<PackageReference Include="Perfolizer" Version="0.2.1" />
23-
<PackageReference Include="System.Management" Version="5.0.0" />
24-
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
25-
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
26-
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
27-
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.2" />
28-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" />
21+
<PackageReference Include="System.Management" Version="6.0.0" />
22+
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
23+
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
24+
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
25+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.0.0" />
2926
<PackageReference Include="Microsoft.Diagnostics.NETCore.Client" Version="0.2.61701" />
3027
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="2.0.61" PrivateAssets="contentfiles;analyzers" />
3128
</ItemGroup>
29+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
30+
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
31+
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
32+
</ItemGroup>
3233
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
3334
<ProjectReference Include="..\BenchmarkDotNet.Disassembler.x64\BenchmarkDotNet.Disassembler.x64.csproj">
3435
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>

src/BenchmarkDotNet/Engines/IEngine.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BenchmarkDotNet.Jobs;
55
using BenchmarkDotNet.Reports;
66
using JetBrains.Annotations;
7+
using NotNullAttribute = JetBrains.Annotations.NotNullAttribute;
78

89
namespace BenchmarkDotNet.Engines
910
{

src/BenchmarkDotNet/Environments/OsBrandStringHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using JetBrains.Annotations;
66
using BenchmarkDotNet.Extensions;
7+
using NotNullAttribute = JetBrains.Annotations.NotNullAttribute;
78

89
namespace BenchmarkDotNet.Environments
910
{

src/BenchmarkDotNet/Environments/ProcessorBrandStringHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using BenchmarkDotNet.Portability.Cpu;
88
using JetBrains.Annotations;
99
using Perfolizer.Horology;
10+
using NotNullAttribute = JetBrains.Annotations.NotNullAttribute;
1011

1112
namespace BenchmarkDotNet.Environments
1213
{

src/BenchmarkDotNet/Extensions/CommonExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ public static void AddRange<T>(this HashSet<T> hashSet, IEnumerable<T> collectio
4242
hashSet.Add(item);
4343
}
4444

45+
#if NETSTANDARD
4546
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
4647
=> dictionary.TryGetValue(key, out var value) ? value : default;
48+
#endif
4749

4850
public static double Sqr(this double x) => x * x;
4951
public static double Pow(this double x, double k) => Math.Pow(x, k);
5052

53+
#if NETSTANDARD
5154
internal static IEnumerable<TItem> DistinctBy<TItem, TValue>(this IEnumerable<TItem> items, Func<TItem, TValue> selector)
5255
=> DistinctBy(items, selector, EqualityComparer<TValue>.Default);
5356

@@ -60,6 +63,7 @@ private static IEnumerable<TItem> DistinctBy<TItem, TValue>(this IEnumerable<TIt
6063
if (seen.Add(selector(item)))
6164
yield return item;
6265
}
66+
#endif
6367

6468
internal static void ForEach<T>(this IList<T> source, Action<T> command)
6569
{

src/BenchmarkDotNet/Extensions/ProcessExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public static bool TrySetAffinity(
8585
if (logger == null)
8686
throw new ArgumentNullException(nameof(logger));
8787

88+
if (!RuntimeInformation.IsWindows() && !RuntimeInformation.IsLinux())
89+
return false;
90+
8891
try
8992
{
9093
process.ProcessorAffinity = FixAffinity(processorAffinity);
@@ -104,6 +107,9 @@ public static bool TrySetAffinity(
104107
if (process == null)
105108
throw new ArgumentNullException(nameof(process));
106109

110+
if (!RuntimeInformation.IsWindows() && !RuntimeInformation.IsLinux())
111+
return null;
112+
107113
try
108114
{
109115
return process.ProcessorAffinity;

src/BenchmarkDotNet/Helpers/FrameworkVersionHelper.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ internal static string MapToReleaseVersion(string servicingVersion)
4949
if (string.Compare(servicingVersion, "4.8") < 0)
5050
return "4.7.2";
5151

52+
// TODO Add support for .NET Framework 4.8.1
5253
return "4.8"; // most probably the last major release of Full .NET Framework
5354
}
5455

5556

57+
#if NET6_0_OR_GREATER
58+
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
59+
#endif
5660
private static int? GetReleaseNumberFromWindowsRegistry()
5761
{
5862
using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
@@ -64,6 +68,9 @@ internal static string MapToReleaseVersion(string servicingVersion)
6468
}
6569
}
6670

71+
#if NET6_0_OR_GREATER
72+
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
73+
#endif
6774
internal static string GetLatestNetDeveloperPackVersion()
6875
{
6976
if (!(GetReleaseNumberFromWindowsRegistry() is int releaseNumber))

src/BenchmarkDotNet/Portability/Cpu/MosCpuInfoProvider.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ namespace BenchmarkDotNet.Portability.Cpu
99
{
1010
internal static class MosCpuInfoProvider
1111
{
12+
#if NET6_0_OR_GREATER
13+
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
14+
#endif
1215
internal static readonly Lazy<CpuInfo> MosCpuInfo = new Lazy<CpuInfo>(Load);
1316

1417
[NotNull]
18+
#if NET6_0_OR_GREATER
19+
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
20+
#endif
1521
private static CpuInfo Load()
1622
{
1723
var processorModelNames = new HashSet<string>();

src/BenchmarkDotNet/Portability/Cpu/SysctlCpuInfoParser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using BenchmarkDotNet.Helpers;
44
using JetBrains.Annotations;
55
using BenchmarkDotNet.Extensions;
6+
using NotNullAttribute = JetBrains.Annotations.NotNullAttribute;
67

78
namespace BenchmarkDotNet.Portability.Cpu
89
{

0 commit comments

Comments
 (0)