Skip to content

Exclude .pdb of non-publishable project references from publish output - #56175

Merged
marcpopMSFT merged 2 commits into
mainfrom
copilot/fix-pdb-copy-issue
Sep 22, 2026
Merged

marcpopMSFT merged 2 commits into
mainfrom
copilot/fix-pdb-copy-issue

Conversation

Copilot AI commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Referenced projects marked IsPublishable=false correctly had their outputs excluded from the publish directory — except for their .pdb file, which was always copied whenever PublishReferencesSymbols=true (the default).

<!-- lib1.csproj -->
<IsPublishable>false</IsPublishable>
$ dotnet publish -o dist   # exe1 references lib1
$ ls dist
exe1  exe1.pdb  exe1.deps.json  exe1.runtimeconfig.json  lib1.dll  lib1.pdb   # lib1.pdb shouldn't be here

Root cause

ReferenceCopyLocalPaths items (populated by MSBuild's assembly reference resolution for project references, including the auto-discovered .pdb sibling of a referenced .dll) carried no information about the referenced project's IsPublishable value, so the publish logic had no signal to exclude it.

Fix

  • Microsoft.NET.Publish.targets: added a target (AfterTargets="GetTargetPathWithTargetPlatformMoniker") that stamps $(IsPublishable) onto @(TargetPathWithTargetPlatformMoniker), the item returned via the standard GetTargetPath project-reference protocol. This metadata flows through to the referencing project's ReferenceCopyLocalPaths items, including the related .pdb.
  • Updated _ComputeResolvedCopyLocalPublishAssets to only copy a referenced .pdb when %(ReferenceCopyLocalPaths.IsPublishable) != 'false'. The referenced .dll is unaffected and still copied, since it's required at run time.

Tests

  • Added It_does_not_publish_symbols_of_a_non_publishable_referenced_project, asserting a referenced project's .dll is published but its .pdb is not when IsPublishable=false.

@azure-pipelines

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

Copilot AI changed the title [WIP] Fix unnecessary .pdb files in publish directory Exclude .pdb of non-publishable project references from publish output Sep 8, 2026
Copilot AI requested a review from marcpopMSFT September 8, 2026 21:16
@marcpopMSFT
marcpopMSFT marked this pull request as ready for review September 21, 2026 22:50
@marcpopMSFT
marcpopMSFT requested review from a team as code owners September 21, 2026 22:50
@marcpopMSFT
marcpopMSFT requested review from dsplaisted and a lite review from Copilot September 21, 2026 22:50
@azure-pipelines

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

@marcpopMSFT

Copy link
Copy Markdown
Member

Tested in codespace that publish of a IsPublishable reference no longer includes the pdb

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.

Copilot review overview

🟢 Approval recommended

No unresolved review issues remain.

Review effort: Lite
Findings: None

What changed in this PR

This pull request excludes .pdb files from non-publishable project references while retaining their required runtime assemblies.

Changes:

  • Propagates IsPublishable metadata through project-reference target paths.
  • Filters non-publishable referenced symbols from publish output.
  • Adds regression test coverage.
File Description
test/​Microsoft.NET.Publish.Tests/​GivenThatWeWantToPublishAProjectWithDependencies.cs Verifies DLL inclusion and PDB exclusion.
src/​Tasks/​Microsoft.NET.Build.Tasks/​targets/​Microsoft.NET.Publish.targets Adds metadata propagation and filters referenced PDBs.

@marcpopMSFT
marcpopMSFT enabled auto-merge (squash) September 22, 2026 20:29

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the separation of the source of the data (the referenced project) from the consumer of the data (the referencing project)!

@marcpopMSFT
marcpopMSFT merged commit ab4b23d into main Sep 22, 2026
25 checks passed
@marcpopMSFT
marcpopMSFT deleted the copilot/fix-pdb-copy-issue branch September 22, 2026 20:30
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 23, 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.

IsPublishable with PublishSingleFile, PublishAot etc. copies unnecessary .pdb to PublishDir

4 participants