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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 8, 2025

This PR implements support for two "global" command-line options in dotnet test when using Microsoft Testing Platform (MTP). These options are processed by the dotnet CLI itself and properly transformed before being passed to individual test applications, rather than being blindly forwarded.

New Options Added

The following options are now available when using Microsoft Testing Platform:

  • --config-file <CONFIG_FILE> - The testconfig.json configuration file to use for test execution
  • --diagnostic-output-directory <DIAGNOSTIC_DIR> - Directory where diagnostic output will be placed

Implementation Details

The implementation follows the same pattern established by the existing --results-directory option (from #50081):

  1. Path Transformation: Options that accept file/directory paths (--config-file, --diagnostic-output-directory) are automatically converted from relative to absolute paths using Path.GetFullPath() based on the current working directory.

  2. Global Processing: These options are handled by the dotnet CLI and not included in the forwarded MSBuild arguments, ensuring they are processed consistently across all test projects.

  3. Microsoft Testing Platform Only: The new options only appear when using Microsoft Testing Platform (determined by dotnet.config file with [dotnet.test.runner] name = Microsoft.Testing.Platform). VSTest continues to work unchanged.

Example Usage

# Enable Microsoft Testing Platform
echo -e "[dotnet.test.runner]\nname = Microsoft.Testing.Platform" > dotnet.config

# Use the new global options
dotnet test \
  --solution MySolution.sln \
  --config-file path/to/testconfig.json \
  --diagnostic-output-directory diagnostics \
  --results-directory TestResults

In this example, if run from /repo/root, the relative paths are transformed to:

  • --config-file /repo/root/path/to/testconfig.json
  • --diagnostic-output-directory /repo/root/diagnostics
  • --results-directory /repo/root/TestResults

This ensures that all test projects receive absolute paths pointing to the same directories relative to where dotnet test was invoked, regardless of the individual project locations.

Testing

  • Options appear correctly in dotnet test --help when using Microsoft Testing Platform
  • Options are properly excluded from VSTest to maintain backward compatibility
  • Path transformation handles both relative and absolute paths correctly
  • Build passes without errors or warnings

Part of #49709.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits August 8, 2025 09:06
…ile, --diagnostic-output-directory, --timeout, --minimum-expected-tests, --maximum-failed-tests

Co-authored-by: Youssef1313 <[email protected]>
…ling of absolute/relative paths

Co-authored-by: Youssef1313 <[email protected]>
@Copilot Copilot AI changed the title [WIP] dotnet test for MTP handling of "global" command-line options Implement global command-line options for dotnet test MTP handling Aug 8, 2025
@Copilot Copilot AI requested a review from Youssef1313 August 8, 2025 09:14
Copilot finished work on behalf of Youssef1313 August 8, 2025 09:14
@Copilot Copilot AI changed the title Implement global command-line options for dotnet test MTP handling Implement global --config-file and --diagnostic-output-directory options for dotnet test MTP Aug 8, 2025
@Copilot Copilot AI requested a review from Youssef1313 August 8, 2025 09:35
Copilot finished work on behalf of Youssef1313 August 8, 2025 09:35
@Youssef1313 Youssef1313 marked this pull request as ready for review August 8, 2025 09:39
@Copilot Copilot AI review requested due to automatic review settings August 8, 2025 09:39
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements support for two new "global" command-line options in dotnet test when using Microsoft Testing Platform (MTP): --config-file and --diagnostic-output-directory. These options are processed by the dotnet CLI and automatically converted to absolute paths before being forwarded to test applications.

Key changes:

  • Added two new command-line options (--config-file and --diagnostic-output-directory) that only appear when using Microsoft Testing Platform
  • Implemented path transformation logic that converts relative paths to absolute paths using Path.GetFullPath()
  • Updated data structures and argument forwarding to handle the new options

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Cli/dotnet/Commands/CliCommandStrings.resx Added resource strings for the new command-line option descriptions and help names
src/Cli/dotnet/Commands/xlf/*.xlf Updated localization files with new resource entries marked as "state=new"
src/Cli/dotnet/Commands/Test/TestingPlatformOptions.cs Defined the two new command-line options with proper descriptions and arity
src/Cli/dotnet/Commands/Test/TestCommandParser.cs Added the new options to the testing platform CLI command
src/Cli/dotnet/Commands/Test/Options.cs Extended PathOptions record to include the new configuration file and diagnostic output directory paths
src/Cli/dotnet/Commands/Test/MSBuildUtility.cs Implemented path transformation logic and updated PathOptions construction
src/Cli/dotnet/Commands/Test/TestApplication.cs Added argument forwarding logic for the new options to test applications
Comments suppressed due to low confidence (1)

@@ -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>The NuGet configuration file to use for the test execution.</value>
Copy link
Member

Choose a reason for hiding this comment

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

@copilot Update the description to:

Specifies a testconfig.json file.

Copilot finished work on behalf of Youssef1313 August 8, 2025 09:50
Co-authored-by: Youssef1313 <[email protected]>
Copilot finished work on behalf of Youssef1313 August 8, 2025 09:57
@Youssef1313 Youssef1313 enabled auto-merge (squash) August 8, 2025 13:54
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.

4 participants