Using the AllowedReferenceRelatedFileExtensions
property as others suggested above works well for me either in project files or via msbuild call as well.
There is one caveat though, which is that it works universally.
If we have a lot of projects that reference each other, this will also remove those pdbs that belong to the bottom projects referenced in top projects as well, not just external pdbs.
A possibility is to fallback to project-based setting and add it only to "bottom" projects, but that still makes it hard to get away with intermediate external references directly in top projects, so I am not sure how to control this properly.
In my opinion, it would be great to find a universal way of getting rid of all pdbs coming from external libraries but keep all pdbs coming from internal project references
One thing that seems to work for golden-means is using a combination as below:
/p:AllowedReferenceRelatedFileExtensions=.xml;.config /p:CopyLocalLockFileAssemblies=false
the CopyLocalLockFileAssemblies
property is set to false to prevent the copying of PDB files from NuGet packages, and the AllowedReferenceRelatedFileExtensions
property is set to exclude ".pdb" files from external NuGet packages, but include all other related files (".xml" and ".config" files). Locally referenced projects that include PDB files will still have their PDB files copied to the output directory during build