Skip to content

Added project name to test run title for DotNetCoreCli@2 - #22509

Open
Jeremy Morren (jeremy-morren) wants to merge 1 commit into
microsoft:masterfrom
jeremy-morren:dotNetCli2
Open

Jeremy Morren (jeremy-morren) wants to merge 1 commit into
microsoft:masterfrom
jeremy-morren:dotNetCli2

Conversation

@jeremy-morren

@jeremy-morren Jeremy Morren (jeremy-morren) commented Sep 14, 2026

Copy link
Copy Markdown

Context

When DotNetCoreCLI@2 runs dotnet test against several projects with publishTestResults: true, all results are published under the single testRunTitle (or the default title). In the Tests tab this shows up as MyTitle_1, MyTitle_2, ..., so you have to open each run to find out which project it belongs to. The usual workaround is one task per test project, with each title hardcoded in the pipeline.

Issues requesting this feature:


Task Name

DotNetCoreCLIV2 (DotNetCoreCLI@2)


Description

Adds an optional appendToTestRunTitle pick list input to the test command:

Value Test run title
(empty, default) Unchanged: one publish of all results under testRunTitle
projectName <testRunTitle> <project file name without extension>, e.g. {testRunTitle} Alpha.Tests
projectPath <testRunTitle> <project path relative to Build.SourcesDirectory>, e.g. {testRunTitle} src/Alpha.Tests/Alpha.Tests.csproj

If testRunTitle is empty, the suffix alone becomes the title.

When the input is set:

  • Each project writes its trx files to its own results directory ($(Agent.TempDirectory)/TestResults_<index>), so results from different projects are never mixed.
  • Results are published right after each project runs, under that project's title. This also happens when the project's tests fail, the same way the existing single publish does.
  • For projectPath, the path is relative to Build.SourcesDirectory, falling back to System.DefaultWorkingDirectory. Separators are normalised to /. A project outside the repository root keeps its path as given.
  • An unrecognised value logs a warning (UnknownAppendToTestRunTitle) and nothing is appended.
  • Both VSTest (--logger trx) and Microsoft.Testing.Platform (--report-trx) are supported. The results directory arguments are now built by one shared helper instead of inline in two places.

Example:

- task: DotNetCoreCLI@2
  inputs:
    command: test
    projects: '**/*.Tests.csproj'
    publishTestResults: true
    testRunTitle: 'Unit Tests'
    appendToTestRunTitle: projectName

Risk Assessment (Low / Medium / High)

Low. The feature is opt-in and the new input defaults to empty, which keeps the existing code path: the same arguments, a single publish of Agent.TempDirectory and the same title. The only change on that path is moving the --logger trx / --report-trx argument strings into a helper; the strings themselves are unchanged.


Change Behind Feature Flag (Yes / No)

No. The change is opt-in through a new input that is off by default, so it doesn't need a feature flag.


Tech Design / Approach

  • Publishing per project needs a separate results directory for each project, because PublishTestResults takes one title for every file it is given. A single shared results directory would mix trx files across projects.
  • I considered a $(TestProjectName)-style placeholder inside testRunTitle (as suggested in Cannot set unique testRunTitle when using dotnet test for multiple projects #19795). I chose a separate input because that placeholder uses the same $(...) syntax as pipeline variable macros. If a pipeline variable with that name exists, the agent replaces the placeholder with its value before the task runs. A pick list has no such collision and can be validated.

Documentation Changes Required (Yes/No)

Yes. The DotNetCoreCLI@2 task reference needs the new appendToTestRunTitle input. The help text in task.json describes it.


Unit Tests Added or Updated (Yes / No)

Yes. Two new L0 tests in Tests/L0.ts:

  • publishtestsAppendProjectName: two projects produce two dotnet invocations and two publishes, titled My Tests Alpha.Tests and My Tests Beta.Tests.
  • publishtestsAppendProjectPath: the same, titled with the repository-relative paths Alpha.Tests/Alpha.Tests.csproj and Beta.Tests/Beta.Tests.csproj.

The existing test command L0 tests cover the default path, where the input is not set.


Additional Testing Performed

TODO: pipeline run(s) with the privately uploaded task (VSTest and MTP, Windows and Linux).


Logging Added/Updated (Yes/No)

Yes. One warning is added for an unrecognised appendToTestRunTitle value. It logs only the input value.


Telemetry Added/Updated (Yes/No)

No.


Rollback Scenario and Process (Yes/No)

Yes. Removing appendToTestRunTitle from a pipeline restores the previous behaviour. Reverting this PR only removes the input.


Dependency Impact Assessed and Regression Tested (Yes/No)

No dependency changes. Only DotNetCoreCLIV2 is touched. TODO: regression run.


Checklist

  • Related issue linked (if applicable)
  • Task version was bumped — see versioning guide
  • Verified the task behaves as expected

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Added a parameter to DotNetCoreCli@2 to allow including the project name in the test run title
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.

1 participant