Skip to content

Implement global --config-file and --diagnostic-output-directory options for dotnet test MTP #50136

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

Merged
merged 7 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Cli/dotnet/Commands/CliCommandStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,19 @@ This is equivalent to deleting project.assets.json.</value>
<value>The directory where the test results will be placed.
The specified directory will be created if it does not exist.</value>
</data>
<data name="CmdConfigFileDescription" xml:space="preserve">
<value>Specifies a testconfig.json file.</value>
</data>
<data name="CmdConfigFilePath" xml:space="preserve">
<value>CONFIG_FILE</value>
</data>
<data name="CmdDiagnosticOutputDirectoryDescription" xml:space="preserve">
<value>Output directory of the diagnostic logging.
If not specified the file will be generated inside the default 'TestResults' directory.</value>
</data>
<data name="CmdDiagnosticOutputDirectoryPath" xml:space="preserve">
<value>DIAGNOSTIC_DIR</value>
</data>
<data name="CmdRootPathName" xml:space="preserve">
<value>ROOT_PATH</value>
</data>
Expand Down
18 changes: 16 additions & 2 deletions src/Cli/dotnet/Commands/Test/MSBuildUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,28 @@ public static BuildOptions GetBuildOptions(ParseResult parseResult, int degreeOf
string? resultsDirectory = parseResult.GetValue(TestingPlatformOptions.ResultsDirectoryOption);
if (resultsDirectory is not null)
{
resultsDirectory = Path.Combine(Directory.GetCurrentDirectory(), resultsDirectory);
resultsDirectory = Path.GetFullPath(resultsDirectory);
}

string? configFile = parseResult.GetValue(TestingPlatformOptions.ConfigFileOption);
if (configFile is not null)
{
configFile = Path.GetFullPath(configFile);
}

string? diagnosticOutputDirectory = parseResult.GetValue(TestingPlatformOptions.DiagnosticOutputDirectoryOption);
if (diagnosticOutputDirectory is not null)
{
diagnosticOutputDirectory = Path.GetFullPath(diagnosticOutputDirectory);
}

PathOptions pathOptions = new(
parseResult.GetValue(TestingPlatformOptions.ProjectOption),
parseResult.GetValue(TestingPlatformOptions.SolutionOption),
parseResult.GetValue(TestingPlatformOptions.DirectoryOption),
resultsDirectory);
resultsDirectory,
configFile,
diagnosticOutputDirectory);

return new BuildOptions(
pathOptions,
Expand Down
5 changes: 3 additions & 2 deletions src/Cli/dotnet/Commands/Test/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.DotNet.Cli.Commands.Test;

internal record TestOptions(bool HasFilterMode, bool IsHelp);

internal record PathOptions(string? ProjectPath, string? SolutionPath, string? DirectoryPath, string? ResultsDirectoryPath);
internal record PathOptions(string? ProjectPath, string? SolutionPath, string? DirectoryPath, string? ResultsDirectoryPath, string? ConfigFilePath, string? DiagnosticOutputDirectoryPath);

internal record BuildOptions(
PathOptions PathOptions,
Expand All @@ -14,5 +14,6 @@ internal record BuildOptions(
Utils.VerbosityOptions? Verbosity,
bool NoLaunchProfile,
bool NoLaunchProfileArguments,
int DegreeOfParallelism, List<string> UnmatchedTokens,
int DegreeOfParallelism,
List<string> UnmatchedTokens,
IEnumerable<string> MSBuildArgs);
10 changes: 10 additions & 0 deletions src/Cli/dotnet/Commands/Test/TestApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ private string GetArguments(TestOptions testOptions)
builder.Append($" {TestingPlatformOptions.ResultsDirectoryOption.Name} {ArgumentEscaper.EscapeSingleArg(resultsDirectoryPath)}");
}

if (_buildOptions.PathOptions.ConfigFilePath is { } configFilePath)
{
builder.Append($" {TestingPlatformOptions.ConfigFileOption.Name} {ArgumentEscaper.EscapeSingleArg(configFilePath)}");
}

if (_buildOptions.PathOptions.DiagnosticOutputDirectoryPath is { } diagnosticOutputDirectoryPath)
{
builder.Append($" {TestingPlatformOptions.DiagnosticOutputDirectoryOption.Name} {ArgumentEscaper.EscapeSingleArg(diagnosticOutputDirectoryPath)}");
}

foreach (var arg in _buildOptions.UnmatchedTokens)
{
builder.Append($" {ArgumentEscaper.EscapeSingleArg(arg)}");
Expand Down
2 changes: 2 additions & 0 deletions src/Cli/dotnet/Commands/Test/TestCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ private static Command GetTestingPlatformCliCommand()
command.Options.Add(TestingPlatformOptions.TestModulesFilterOption);
command.Options.Add(TestingPlatformOptions.TestModulesRootDirectoryOption);
command.Options.Add(TestingPlatformOptions.ResultsDirectoryOption);
command.Options.Add(TestingPlatformOptions.ConfigFileOption);
command.Options.Add(TestingPlatformOptions.DiagnosticOutputDirectoryOption);
command.Options.Add(TestingPlatformOptions.MaxParallelTestModulesOption);
command.Options.Add(CommonOptions.ArchitectureOption);
command.Options.Add(CommonOptions.PropertiesOption);
Expand Down
14 changes: 14 additions & 0 deletions src/Cli/dotnet/Commands/Test/TestingPlatformOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ internal static class TestingPlatformOptions
Arity = ArgumentArity.ExactlyOne
};

public static readonly Option<string> ConfigFileOption = new("--config-file")
{
Description = CliCommandStrings.CmdConfigFileDescription,
HelpName = CliCommandStrings.CmdConfigFilePath,
Arity = ArgumentArity.ExactlyOne
};

public static readonly Option<string> DiagnosticOutputDirectoryOption = new("--diagnostic-output-directory")
{
Description = CliCommandStrings.CmdDiagnosticOutputDirectoryDescription,
HelpName = CliCommandStrings.CmdDiagnosticOutputDirectoryPath,
Arity = ArgumentArity.ExactlyOne
};

public static readonly Option<string> MaxParallelTestModulesOption = new("--max-parallel-test-modules")
{
Description = CliCommandStrings.CmdMaxParallelTestModulesDescription,
Expand Down
22 changes: 22 additions & 0 deletions src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading