Closed
Description
I'm unable to apply MsBuildArgument
s to benchmarks, the toy solution below exhibits the bug
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
var config = ManualConfig.Create(DefaultConfig.Instance)
.WithOptions(ConfigOptions.DisableOptimizationsValidator);
BenchmarkSwitcher.FromAssemblies(
new[] {
typeof(Program).Assembly
}
).Run(args, config);
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
[Config(typeof(AConfig))]
public class A
{
public class AConfig : ManualConfig
{
public AConfig()
{
AddJob(
Job.Default
.WithRuntime(CoreRuntime.Core60)
.WithId("Baseline")
.AsBaseline()
);
AddJob(
Job.Default
.WithArguments(new[] { new MsBuildArgument(@"-p:MY_PREPROCESSOR_DIRECTIVE=""true""") })
.WithRuntime(CoreRuntime.Core60)
.WithId("MY_PREPROCESSOR_DIRECTIVE")
);
}
}
[Benchmark]
public void ScopeCommit()
{
#if MY_PREPROCESSOR_DIRECTIVE
#error MY_PREPROCESSOR_DIRECTIVE set
#endif
var a = 1 + 1;
a++;
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.10" />
</ItemGroup>
<PropertyGroup Condition="'$(MY_PREPROCESSOR_DIRECTIVE)'=='true'">
<DefineConstants>$(DefineConstants);MY_PREPROCESSOR_DIRECTIVE</DefineConstants>
</PropertyGroup>
</Project>
If I run msBuild directly it compiles as expected dotnet build -p:MY_PREPROCESSOR_DIRECTIVE="true"
MSBuild version 17.7.4+3ebbd7c49 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
[...]
C:\code\Adaptive.Integration.Benchmark\A.cs(52,12): error CS1029: #error: 'MY_PREPROCESSOR_DIRECTIVE set' [C:\code\Benchmark\Benchmark.csproj]
Build FAILED.
C:\code\Benchmark\A.cs(52,12): error CS1029: #error: 'MY_PREPROCESSOR_DIRECTIVE set' [C:\code\Benchmark\Benchmark.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:06.05