Skip to content

feat: Add API to set custom DefaultConfig.Instance#3051

Open
filzrev wants to merge 1 commit intodotnet:masterfrom
filzrev:feat-add-feature-to-customize-defaultconfig
Open

feat: Add API to set custom DefaultConfig.Instance#3051
filzrev wants to merge 1 commit intodotnet:masterfrom
filzrev:feat-add-feature-to-customize-defaultconfig

Conversation

@filzrev
Copy link
Contributor

@filzrev filzrev commented Mar 14, 2026

This PR add DefaultConfig.SetDefault(config) API to customize default global config.

Background
BenchmarkDotNet use DefaultConfig.Instance when global config is not passed to BenchmarkRunner/BenchmarkSwitcher.

On normarl use case, It can specify global config by using Main entry point.
But when running benchmark via TestAdaper, It can't use Main entry point (and launchsettings.json)
So. it need to customize config via assembly-level ConfigAttribute.
https://benchmarkdotnet.org/articles/features/vstest.html?q=testadapter#setting-a-default-configuration

This PR add DefaultConfig.SetDefault(config) API.
By this change, it can use custom config by TestAdapter, (Settings are loaded from .runsettings/testconfig.json)

@timcassell
Copy link
Collaborator

How is it expected to be used? The test adapter supports providing your own entry point by setting <GenerateProgramFile>false</GenerateProgramFile>.

@filzrev
Copy link
Contributor Author

filzrev commented Mar 14, 2026

How is it expected to be used?

It's needed when running benchmarks from VS TestExplorer.

When running benchmark via TestExplorer.
It always use DefaultConfig.Instance because Program.cs entry point is not used.
I want to customize this behavior by this PR.

@timcassell
Copy link
Collaborator

It's needed when running benchmarks from VS TestExplorer.

Right, you said that already, but it doesn't explain how.

@filzrev
Copy link
Contributor Author

filzrev commented Mar 15, 2026

Right, you said that already, but it doesn't explain how.

The following code is expected API usage on VSTestAdapter (with VsTest).
filzrev@c438bd3

By this changes, It can specify custom arguments when running benchmark on Test Explorer.

{
}

public static void SetDefault(IConfig? config)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is misleading, it's actually setting Instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants