diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets index 5e59cd8b400d..3dcad3888e55 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets @@ -703,7 +703,10 @@ Copyright (c) .NET Foundation. All rights reserved. <_ResolvedCopyLocalPublishAssets Include="@(ReferenceCopyLocalPaths)" Exclude="@(_ResolvedCopyLocalBuildAssets);@(RuntimePackAsset)" - Condition="('$(PublishReferencesDocumentationFiles)' == 'true' or '%(ReferenceCopyLocalPaths.Extension)' != '.xml') and '%(ReferenceCopyLocalPaths.Private)' != 'false'"> + Condition="(('$(PublishReferencesDocumentationFiles)' == 'true' and '%(ReferenceCopyLocalPaths.Extension)' == '.xml') + or ('$(PublishReferencesSymbols)' == 'true' and '%(ReferenceCopyLocalPaths.Extension)' == '.pdb') + or ('%(ReferenceCopyLocalPaths.Extension)' != '.xml' and '%(ReferenceCopyLocalPaths.Extension)' != '.pdb')) + and '%(ReferenceCopyLocalPaths.Private)' != 'false'"> %(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets index 0b94c1b0cbb5..7c94705bd5d4 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets @@ -291,6 +291,7 @@ Copyright (c) .NET Foundation. All rights reserved. true true true + true diff --git a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs index 9010d3dc1677..e62928fab01b 100644 --- a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs +++ b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs @@ -277,6 +277,33 @@ public void It_publishes_referenced_assembly_documentation(string property, bool } } + [Theory] + [InlineData("PublishReferencesSymbols=false", false)] + [InlineData("PublishReferencesSymbols=true", true)] + public void It_publishes_referenced_project_symbol(string property, bool expectReferenceSymbol) + { + var kitchenSinkAsset = _testAssetsManager + .CopyTestAsset("KitchenSink", identifier: $"{property.Replace("=", "")}") + .WithSource(); + + var publishCommand = new PublishCommand(kitchenSinkAsset, "TestApp"); + var publishArgs = new string[] { $"/p:{property}" }; + var publishResult = publishCommand.Execute(publishArgs); + + publishResult.Should().Pass(); + + var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: ToolsetInfo.CurrentTargetFramework); + + if (expectReferenceSymbol) + { + publishDirectory.Should().HaveFile("TestLibrary.pdb"); + } + else + { + publishDirectory.Should().NotHaveFile("TestLibrary.pdb"); + } + } + private static JObject ReadJson(string path) { using (JsonTextReader jsonReader = new(File.OpenText(path)))