You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
--coverage-output flag silently omits/deletes output files when solution has multiple test projects #56930
If dotnet test --coverage is run with the flag --coverage-output in a solution with multiple test projects, there will be a report from only one of the test projects
Steps to reproduce
Create a solution with two test projects using MTP
Run dotnet test --coverage --coverage-output-format cobertura --coverage-output my-output-file.xml
➡️ Summary: With --coverage-output and multiple MTP test projects, coverage output from all but one project is silently overwritten. Consider failing or warning when the output path is shared across projects.
Generated by 🏷️ Issue Triage for #56930 · copilot · auto · 20.1 AIC · ⌖ 0.68 AIC · ⊞ 14.6K · ◷
Thanks for the minimal reproduction. I confirmed the behavior with .NET SDK 10.0.403 and 11.0.100-rc.3, using Microsoft.Testing.Extensions.CodeCoverage 18.12.0: both test projects pass, but only one project's coverage survives when they use the same explicit output filename.
Why the behavior changed
This is a consequence of fixing an earlier bug in how dotnet test and Microsoft.Testing.Platform resolved working and results directories.
Previously, each test application resolved its default TestResults directory relative to its own output directory. That meant test applications belonging to the same dotnet test invocation did not share the common results-directory root, and relative paths could resolve differently between applications.
The fixes in #52570 and microsoft/testfx#7265 made the SDK communicate the original invocation directory and made MTP honor it. Results now consistently go into the shared TestResults directory beneath the directory where dotnet test was invoked, unless configured otherwise.
Unfortunately, that exposed a collision for explicit filenames: a name that previously landed in separate directories now points to the same file for every test application. --coverage-output my-output-file.xml is forwarded to each application; it does not request a single combined solution-level report. Each application writes its own report, overwriting the previous contents. Serializing execution does not prevent this.
How to preserve all coverage reports
If you do not need a fixed filename, omit --coverage-output:
dotnet test --coverage --coverage-output-format cobertura
The coverage extension generates unique GUID-based filenames, so each application's report is preserved. With the SDK 11 version tested, those distinct reports are also automatically merged into a combined coverage report.
If you need to keep a fixed filename, use the per-module results layout:
dotnet test --coverage --coverage-output-format cobertura --coverage-output my-output-file.xml --results-directory-layout per-module
This option was added in #55475 and backported to the .NET SDK 10.0.4xx branch in #55629, including SDK 10.0.403. For your example, it separates the reports into paths such as:
This applies to a relative filename; explicitly directing every application to the same absolute coverage-output path would still collide.
The default layout remains flat for compatibility, so the shared-directory fix and the per-module option do not themselves add a warning for your original command. You are right that reporting success without warning about the lost coverage is easy to miss. The explanation above accounts for the behavior change, but the request for a clear warning or failure remains a separate concern.
Activity
computaserik commentedon Nov 4, 2026
The only hint I found of this behaviour is buried in xUnit documentation: https://xunit.net/docs/getting-started/v3/code-coverage-with-mtp#enabling-code-coverage
github-actions commentedon Nov 4, 2026
🎯 Agentic Issue Triage
Triage Assessment:
@dotnet/dotnet-testingmedium- Clearly adotnet testMTP issue, but the owning team has no expandable members for assignment.Similar issues: #56796 (
potentially related)➡️ Summary: With
--coverage-outputand multiple MTP test projects, coverage output from all but one project is silently overwritten. Consider failing or warning when the output path is shared across projects.Evangelink commentedon Nov 5, 2026
Thanks for the minimal reproduction. I confirmed the behavior with .NET SDK 10.0.403 and 11.0.100-rc.3, using
Microsoft.Testing.Extensions.CodeCoverage18.12.0: both test projects pass, but only one project's coverage survives when they use the same explicit output filename.Why the behavior changed
This is a consequence of fixing an earlier bug in how
dotnet testand Microsoft.Testing.Platform resolved working and results directories.Previously, each test application resolved its default
TestResultsdirectory relative to its own output directory. That meant test applications belonging to the samedotnet testinvocation did not share the common results-directory root, and relative paths could resolve differently between applications.The fixes in #52570 and microsoft/testfx#7265 made the SDK communicate the original invocation directory and made MTP honor it. Results now consistently go into the shared
TestResultsdirectory beneath the directory wheredotnet testwas invoked, unless configured otherwise.Unfortunately, that exposed a collision for explicit filenames: a name that previously landed in separate directories now points to the same file for every test application.
--coverage-output my-output-file.xmlis forwarded to each application; it does not request a single combined solution-level report. Each application writes its own report, overwriting the previous contents. Serializing execution does not prevent this.How to preserve all coverage reports
If you do not need a fixed filename, omit
--coverage-output:dotnet test --coverage --coverage-output-format coberturaThe coverage extension generates unique GUID-based filenames, so each application's report is preserved. With the SDK 11 version tested, those distinct reports are also automatically merged into a combined coverage report.
If you need to keep a fixed filename, use the per-module results layout:
dotnet test --coverage --coverage-output-format cobertura --coverage-output my-output-file.xml --results-directory-layout per-moduleThis option was added in #55475 and backported to the .NET SDK 10.0.4xx branch in #55629, including SDK 10.0.403. For your example, it separates the reports into paths such as:
This applies to a relative filename; explicitly directing every application to the same absolute coverage-output path would still collide.
The default layout remains
flatfor compatibility, so the shared-directory fix and the per-module option do not themselves add a warning for your original command. You are right that reporting success without warning about the lost coverage is easy to miss. The explanation above accounts for the behavior change, but the request for a clear warning or failure remains a separate concern.