Skip to content

Respect SatelliteResourceLanguages in Microsoft.CodeCoverage.targets - #16811

Open
Yitzhak Steinmetz (yitzhaks) wants to merge 2 commits into
microsoft:mainfrom
yitzhaks:respect-satellite-resource-languages-in-codecoverage
Open

Yitzhak Steinmetz (yitzhaks) wants to merge 2 commits into
microsoft:mainfrom
yitzhaks:respect-satellite-resource-languages-in-codecoverage

Conversation

@yitzhaks

@yitzhaks Yitzhak Steinmetz (yitzhaks) commented Dec 5, 2026 •

Copy link
Copy Markdown

Description

Summary

Microsoft.CodeCoverage's CopyTraceDataCollectorArtifacts target (AfterTargets="ComputeFilesToPublish") runs after the .NET SDK's _FilterSatelliteResourcesForPublish target and previously added all files under $(MSBuildThisFileDirectory)\**\*.* unconditionally to ResolvedFileToPublish. As a result, setting SatelliteResourceLanguages (for example en-US) had no effect on the 13 localized culture folders (cs, de, es, fr, it, ja, ko, pl, pt-BR, ru, tr, zh-Hans, zh-Hant) of Microsoft.VisualStudio.TraceDataCollector.resources.dll and Microsoft.CodeCoverage.Core.resources.dll copied during dotnet publish.

This change updates CopyTraceDataCollectorArtifacts in src/package/Microsoft.CodeCoverage/Microsoft.CodeCoverage.targets to filter localized *.resources.dll items in TraceDataCollectorArtifacts by their culture subfolder against $(SatelliteResourceLanguages) (case-insensitive, matching .NET SDK's _FilterSatelliteResourcesForPublish and MSTest.TestAdapter):

  • When $(SatelliteResourceLanguages) is unset, empty, or contains no non-empty language entries (e.g., whitespace/semicolon-only), behavior is unchanged and all localized satellite folders are preserved.
  • When $(SatelliteResourceLanguages) contains one or more language entries, only localized *.resources.dll files whose culture folder matches one of the specified languages are included; all non-satellite collector assemblies, native binaries, and config/target files remain unaffected.

Impact

  • Smaller, cleaner publish outputs: Eliminates up to 26 unused satellite assemblies across 13 culture directories per published project/TFM when SatelliteResourceLanguages excludes those locales (compounding across large multi-project and multi-targeted repositories, packaging manifests, and CI/deployment drops).
  • Consistent SatelliteResourceLanguages semantics: Aligns Microsoft.CodeCoverage with standard .NET SDK publish filtering and MSTest.TestAdapter.
  • Backward compatible: Projects that do not set SatelliteResourceLanguages see no behavioral change. Projects that set SatelliteResourceLanguages retain all non-satellite code coverage binaries and can still collect coverage from published outputs as before.

Validation

  • Built and packed in Release configuration (.\build.cmd -c Release -pack) and ran .\eng\verify-nupkgs.ps1.
  • Added acceptance tests in test/Microsoft.TestPlatform.Acceptance.IntegrationTests/CodeCoveragePublishTests.cs:
    • PublishRespectsSatelliteResourceLanguages covering unset, empty, whitespace-only (" "), semicolon/whitespace-only (" ; "), en-US, multi-locale (en-US;fr;de), mixed-case/whitespace-padded (en-US; PT-br ; ZH-HANS ), and nested culture subdirectories (CodeCoverage/fr/...).
    • PublishedTestsRespectSatelliteResourceLanguages verifying end-to-end dotnet publish -p:SatelliteResourceLanguages=en-US with the locally packed Microsoft.CodeCoverage package copies zero *.resources.dll files while dotnet vstest /collect:"Code Coverage;Format=cobertura" still succeeds and produces coverage.
  • All 13 test cases in CodeCoveragePublishTests pass in Release.

Related issue

Relates to #2057.

CopyTraceDataCollectorArtifacts runs after ComputeFilesToPublish (and therefore
after the .NET SDK's _FilterSatelliteResourcesForPublish target) and previously
added all localized *.resources.dll files from build\netstandard2.0\<culture>\
unconditionally to ResolvedFileToPublish.

Filter localized *.resources.dll items in TraceDataCollectorArtifacts against
$(SatelliteResourceLanguages) (case-insensitive) when set, leaving behavior
unchanged when SatelliteResourceLanguages is unset or empty.

Add acceptance tests covering unset, empty, single-locale, multi-locale,
case-insensitive/whitespace-padded lists, and end-to-end published coverage
collection with SatelliteResourceLanguages=en-US.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f3af7923-4d0e-4868-8504-a1d24c0b941f
Copilot AI balanced review requested due to automatic review settings December 5, 2026 19:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The satellite resource filtering change has no active review issues.

No open issues 🎉

What changed in this PR

Updates VSTest’s code coverage publishing to honor SatelliteResourceLanguages, addressing the localized resources left in publish output described in #2057.

Changes:

  • Filters satellite assemblies by requested cultures while preserving non-satellite files and existing behavior when the property is empty.
  • Adds acceptance tests for language filtering and coverage collection after publishing.
File Description
test/​Microsoft.TestPlatform.Acceptance.IntegrationTests/​CodeCoveragePublishTests.cs Tests culture filtering and published coverage collection.
src/​package/​Microsoft.CodeCoverage/​Microsoft.CodeCoverage.targets Filters published satellite resources by requested languages.

Review effort: Balanced

Gate the satellite filtering PropertyGroup and ItemGroup in
CopyTraceDataCollectorArtifacts on '@(_MsCoverageSatelliteResourceLanguages)' != ''
so whitespace-only or semicolon-only values (which expand to an empty item list)
preserve all satellites instead of stripping them.

Expand PublishRespectsSatelliteResourceLanguages to cover whitespace-only,
semicolon-only, and nested culture directory cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f3af7923-4d0e-4868-8504-a1d24c0b941f
Copilot AI balanced review requested due to automatic review settings December 6, 2026 06:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The unsupported Update attribute inside CopyTraceDataCollectorArtifacts causes MSBuild to fail when importing the targets file, even when SatelliteResourceLanguages is unset.

1 open issue

Review effort: Balanced

Condition="'%(TraceDataCollectorArtifacts.RecursiveDir)' != '' and $([System.String]::Copy('%(TraceDataCollectorArtifacts.Filename)%(TraceDataCollectorArtifacts.Extension)').ToLowerInvariant().EndsWith('.resources.dll'))">
<_Culture>$([System.String]::Copy('%(TraceDataCollectorArtifacts.RecursiveDir)').TrimEnd('\').TrimEnd('/'))</_Culture>
</_MsCoverageSatelliteArtifacts>
<_MsCoverageSatelliteArtifacts Update="@(_MsCoverageSatelliteArtifacts)">

This branch has not been deployed

No deployments
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