Skip to content

Commit

Permalink
Cleanup dependencies and add net6.0 TFM (#2012)
Browse files Browse the repository at this point in the history
* 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).
  • Loading branch information
martincostello committed Jul 15, 2022
1 parent 23f9958 commit 762b76c
Show file tree
Hide file tree
Showing 18 changed files with 412 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ artifacts/*
BDN.Generated
BenchmarkDotNet.Samples/Properties/launchSettings.json
src/BenchmarkDotNet/Disassemblers/net461/*
src/BenchmarkDotNet/Disassemblers/BenchmarkDotNet.Disassembler.*.nupkg

# Visual Studio 2015 cache/options directory
.vs/
Expand Down
19 changes: 10 additions & 9 deletions src/BenchmarkDotNet/BenchmarkDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<AssemblyTitle>BenchmarkDotNet</AssemblyTitle>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);1701;1702;1705;1591;3005;NU1702;CS3001;CS3003</NoWarn>
<AssemblyName>BenchmarkDotNet</AssemblyName>
Expand All @@ -17,18 +17,19 @@
<PackageReference Include="CommandLineParser" Version="2.4.3" />
<PackageReference Include="Iced" Version="1.17.0" />
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="1.1.126102" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Perfolizer" Version="0.2.1" />
<PackageReference Include="System.Management" Version="5.0.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" />
<PackageReference Include="System.Management" Version="6.0.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.0.0" />
<PackageReference Include="Microsoft.Diagnostics.NETCore.Client" Version="0.2.61701" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="2.0.61" PrivateAssets="contentfiles;analyzers" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<ProjectReference Include="..\BenchmarkDotNet.Disassembler.x64\BenchmarkDotNet.Disassembler.x64.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
Expand Down
1 change: 1 addition & 0 deletions src/BenchmarkDotNet/Engines/IEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using JetBrains.Annotations;
using NotNullAttribute = JetBrains.Annotations.NotNullAttribute;

namespace BenchmarkDotNet.Engines
{
Expand Down
1 change: 1 addition & 0 deletions src/BenchmarkDotNet/Environments/OsBrandStringHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using JetBrains.Annotations;
using BenchmarkDotNet.Extensions;
using NotNullAttribute = JetBrains.Annotations.NotNullAttribute;

namespace BenchmarkDotNet.Environments
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using BenchmarkDotNet.Portability.Cpu;
using JetBrains.Annotations;
using Perfolizer.Horology;
using NotNullAttribute = JetBrains.Annotations.NotNullAttribute;

namespace BenchmarkDotNet.Environments
{
Expand Down
4 changes: 4 additions & 0 deletions src/BenchmarkDotNet/Extensions/CommonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ public static void AddRange<T>(this HashSet<T> hashSet, IEnumerable<T> collectio
hashSet.Add(item);
}

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

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

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

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

internal static void ForEach<T>(this IList<T> source, Action<T> command)
{
Expand Down
6 changes: 6 additions & 0 deletions src/BenchmarkDotNet/Extensions/ProcessExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public static bool TrySetAffinity(
if (logger == null)
throw new ArgumentNullException(nameof(logger));

if (!RuntimeInformation.IsWindows() && !RuntimeInformation.IsLinux())
return false;

try
{
process.ProcessorAffinity = FixAffinity(processorAffinity);
Expand All @@ -104,6 +107,9 @@ public static bool TrySetAffinity(
if (process == null)
throw new ArgumentNullException(nameof(process));

if (!RuntimeInformation.IsWindows() && !RuntimeInformation.IsLinux())
return null;

try
{
return process.ProcessorAffinity;
Expand Down
7 changes: 7 additions & 0 deletions src/BenchmarkDotNet/Helpers/FrameworkVersionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ internal static string MapToReleaseVersion(string servicingVersion)
if (string.Compare(servicingVersion, "4.8") < 0)
return "4.7.2";

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


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

#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
internal static string GetLatestNetDeveloperPackVersion()
{
if (!(GetReleaseNumberFromWindowsRegistry() is int releaseNumber))
Expand Down
6 changes: 6 additions & 0 deletions src/BenchmarkDotNet/Portability/Cpu/MosCpuInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ namespace BenchmarkDotNet.Portability.Cpu
{
internal static class MosCpuInfoProvider
{
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
internal static readonly Lazy<CpuInfo> MosCpuInfo = new Lazy<CpuInfo>(Load);

[NotNull]
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
private static CpuInfo Load()
{
var processorModelNames = new HashSet<string>();
Expand Down
1 change: 1 addition & 0 deletions src/BenchmarkDotNet/Portability/Cpu/SysctlCpuInfoParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BenchmarkDotNet.Helpers;
using JetBrains.Annotations;
using BenchmarkDotNet.Extensions;
using NotNullAttribute = JetBrains.Annotations.NotNullAttribute;

namespace BenchmarkDotNet.Portability.Cpu
{
Expand Down
Loading

0 comments on commit 762b76c

Please sign in to comment.