-
-
Notifications
You must be signed in to change notification settings - Fork 991
MSBuild Params Not Applied to Benchamrk #2477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I am able to reproduce with the following code: using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
namespace BdnReproMsBuildArgs
{
public class Program
{
static void Main(string[] args)
{
var config = ManualConfig.Create(DefaultConfig.Instance)
.WithOptions(ConfigOptions.DisableOptimizationsValidator)
.AddJob(Job.Dry
.WithArguments(new[] { new MsBuildArgument("/p:MY_PREPROCESSOR_DIRECTIVE=true") }));
BenchmarkSwitcher
.FromAssemblies(new[] { typeof(Program).Assembly })
.RunAll(config, args);
}
[Benchmark]
public void ScopeCommit()
{
#if MY_PREPROCESSOR_DIRECTIVE
#error MY_PREPROCESSOR_DIRECTIVE set
#endif
var a = 1 + 1;
a++;
}
}
} Let me take a quick look. |
OK, I've enabled the build output logging with: .WithOptions(ConfigOptions.DisableOptimizationsValidator | ConfigOptions.LogBuildOutput) In the log I can see following output:
The interesting part is:
So what BDN does is trying to perform full build (dependencies included), the build fails and it falls back to dotnet build Should it just fail? Yes, but it would be hard on our side to distinguish such failures from actual build failures. When I change the benchmark to simply do something else when the directive is set: using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
namespace BdnReproMsBuildArgs
{
public class Program
{
static void Main(string[] args)
{
var config = ManualConfig.Create(DefaultConfig.Instance)
.WithOptions(ConfigOptions.DisableOptimizationsValidator | ConfigOptions.LogBuildOutput)
//.AddJob(Job.Dry)
.AddJob(Job.Dry
.WithArguments(new[] { new MsBuildArgument("/p:MY_PREPROCESSOR_DIRECTIVE=true") }));
BenchmarkSwitcher
.FromAssemblies(new[] { typeof(Program).Assembly })
.RunAll(config, args);
}
[Benchmark]
public void ScopeCommit()
{
#if MY_PREPROCESSOR_DIRECTIVE
Thread.Sleep(TimeSpan.FromSeconds(10));
#else
Thread.Sleep(TimeSpan.FromSeconds(1));
#endif
}
}
} The build also fails, but with different error: the file is in use, so it can not be rebuilt:
What I can offer right now is a workaround: use .AddJob(Job.Dry.WithCustomBuildConfiguration("MY_PREPROCESSOR_DIRECTIVE")); Once you do that you won't need the following logic: <PropertyGroup Condition="'$(MY_PREPROCESSOR_DIRECTIVE)'=='true'">
<DefineConstants>$(DefineConstants);MY_PREPROCESSOR_DIRECTIVE</DefineConstants>
</PropertyGroup> Moreover, you can also remove |
Thanks for following up! I was trying to use the build failure as a sanity test and never assumed it'd be swallowed. Regardless, thank you so much! |
This will be fixed by #2393. |
I'm unable to apply
MsBuildArgument
s to benchmarks, the toy solution below exhibits the bugIf I run msBuild directly it compiles as expected
dotnet build -p:MY_PREPROCESSOR_DIRECTIVE="true"
The text was updated successfully, but these errors were encountered: