From 580a6cce0f48c7de2c99a416a0e0a56559317f0e Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Wed, 17 Jun 2020 03:43:40 +0200 Subject: [PATCH] BDN workaround for netcoreapp5.0->net5.0 moniker rebranding (#23000) --- src/Shared/BenchmarkRunner/Program.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Shared/BenchmarkRunner/Program.cs b/src/Shared/BenchmarkRunner/Program.cs index 87a01cf6c2..70543ad2d3 100644 --- a/src/Shared/BenchmarkRunner/Program.cs +++ b/src/Shared/BenchmarkRunner/Program.cs @@ -9,7 +9,10 @@ using System.Reflection; using System.Text; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Running; +using BenchmarkDotNet.Toolchains.CsProj; +using BenchmarkDotNet.Toolchains.DotNetCli; namespace Microsoft.AspNetCore.BenchmarkDotNet.Runner { @@ -26,7 +29,7 @@ namespace Microsoft.AspNetCore.BenchmarkDotNet.Runner AssignConfiguration(ref args); var summaries = BenchmarkSwitcher.FromAssembly(typeof(Program).GetTypeInfo().Assembly) - .Run(args, ManualConfig.CreateEmpty()); + .Run(args, GetConfig()); foreach (var summary in summaries) { @@ -57,6 +60,24 @@ namespace Microsoft.AspNetCore.BenchmarkDotNet.Runner return 0; } + private static IConfig GetConfig() + { +#if NET5_0 || NETCOREAPP5_0 + return ManualConfig.CreateEmpty() + .AddJob(Job.Default + .WithToolchain(CsProjCoreToolchain.From(new NetCoreAppSettings + ( + // not using "net5.0", a workaround for https://github.com/dotnet/BenchmarkDotNet/pull/1479 + targetFrameworkMoniker: "netcoreapp5.0", + runtimeFrameworkVersion: default, + name: ".NET Core 5.0" + ))) + .AsDefault()); +#else + return ManualConfig.CreateEmpty(); +#endif + } + private static int Fail(object o, string message) { _standardOutput?.WriteLine(_standardOutputText.ToString());