Skip to content

Avoid code coverage artifacts overwriting publish files - #8346

Closed
dsplaisted wants to merge 3 commits into
dotnet:release/10.0.4xxfrom
dsplaisted:dsplaisted-fix-codecoverage-publish-collision
Closed

dsplaisted wants to merge 3 commits into
dotnet:release/10.0.4xxfrom
dsplaisted:dsplaisted-fix-codecoverage-publish-collision

Conversation

@dsplaisted

@dsplaisted dsplaisted commented Aug 17, 2026 •

Copy link
Copy Markdown
Member

Fix issue that surfaced in dotnet/sdk#55754. During publish, Microsoft.CodeCoverage.targets replaced application assemblies—especially System.Text.Json 10.0.0.11 and System.Memory 4.0.5.0—with older CodeCoverage-private copies (6.0.0.0 and 4.0.1.1). This caused assembly loading failures in the net472 tests. For example:

System.TypeInitializationException : The type initializer for 'Microsoft.NET.Sdk.Publish.Tasks.HttpClientExtensions' threw an exception.
---- System.IO.FileLoadException : Could not load file or assembly 'System.Text.Json, Version=10.0.0.11, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

It looks like previously a subsequent publish copy with _CopyResolvedFilesToPublishPreserveNewest would overwrite the older files from the code coverage package, but now the code coverage package ended up with newer timestamps on the older assemblies, leading to this issue.

Description

Microsoft.CodeCoverage.targets copied the entire collector tree after ComputeFilesToPublish, allowing collector dependencies such as System.Memory.dll to overwrite application-owned publish files. This change assigns collector artifacts their publish-relative paths and removes any path already owned by ResolvedFileToPublish using path-like metadata matching, while continuing to publish unique collector artifacts.

A focused regression test executes the packaged target with an intentionally newer colliding collector file. It verifies that the application-owned file wins regardless of timestamps and that a unique nested coverage artifact is still copied.

Skip code coverage artifacts whose publish-relative path is already owned by ResolvedFileToPublish, while preserving unique collector artifacts.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 5058191f-b8c2-493e-96fd-07c5ee938a1b
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team August 17, 2026 10:31
Run the synthetic project through the installed MSBuild toolset so the standard Copy task is registered without adding Microsoft.Build.Tasks.Core and its vulnerable transitive dependency.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1031e116-e457-42a0-9c9c-828732a012dd
Run the synthetic publish project through AcceptanceTestBase so the regression uses the repository's temporary-directory, patched-dotnet, process timeout, and output-capture conventions.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 1031e116-e457-42a0-9c9c-828732a012dd
@akoeplinger

Copy link
Copy Markdown
Member

It looks like previously a subsequent publish copy with _CopyResolvedFilesToPublishPreserveNewest would overwrite the older files from the code coverage package, but now the code coverage package ended up with newer timestamps on the older assemblies, leading to this issue.

@omajid this sounds quite similar to NuGet/Home#15050 which was triggered by the deterministic pack timestamp changes. I wonder if we should make that part opt-in instead.

@omajid

omajid commented Aug 18, 2026

Copy link
Copy Markdown
Member

Yes, we seem to be running into too many unexpected regressions.

@akoeplinger

Copy link
Copy Markdown
Member

@omajid are you going to open a nuget-client PR?

@dsplaisted

Copy link
Copy Markdown
Member Author

@dotnet/dotnet-testing-admin Thoughts on this? It looks like the issue was exposed by deterministic timestamps in NuGet packages, but there probably needs to be a fix in how the code coverage targets copy dependencies.

@nohwnd

nohwnd commented Aug 26, 2026

Copy link
Copy Markdown
Member

@fhnaseer please have a look on this code coverage issue.

@fhnaseer

Copy link
Copy Markdown
Member

@nohwnd Can you make the changes in this pr directly to vstest?

@omajid

omajid commented Aug 26, 2026

Copy link
Copy Markdown
Member

@omajid are you going to open a nuget-client PR?

Sorry, I was swamped with other things.

@akoeplinger

Copy link
Copy Markdown
Member

given deterministic pack was disabled by default again (NuGet/NuGet.Client#7652) we don't need this anymore.

@akoeplinger akoeplinger closed this Oct 7, 2026
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.

5 participants