I'm trying to include PDB files of project references into Nuget package, by using dotnet pack command.
I've found solution to include project referenced DLL files into nuget package. This needs adding some code to .csproj file. I've also tried to make it work with .pdb files, but this doesn't work.
This code copy only *.dll files to nuget.
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
<ItemGroup>
<BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))"/>
</ItemGroup>
</Target>
This is what i tried, but *.pdb files aren't visible in nuget.
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
<ItemGroup>
<BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->Replace('.dll', '.pdb'))"/>
</ItemGroup>
</Target>
SOLUTION
I've fund solution to copy referenced PDB's- just add this lines to your .csproj file:
<Target Name="CopyPdbToPackage" Inputs="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" Outputs="%(ProjectReference.Identity)" AfterTargets="CopyProjectReferencesToPackage">
<PropertyGroup>
<CurrentReference>%(ProjectReference.Identity)</CurrentReference>
<CurrentReferenceName>$([System.IO.Path]::GetFileNameWithoutExtension($(CurrentReference)))</CurrentReferenceName>
</PropertyGroup>
<Message Text="Copying PDB of $(CurrentReferenceName) to packages..." Importance="high" Condition="'%(ProjectReference.NugetIgnore)'!='true'" />
<ItemGroup>
<AllItems Include="@(ReferenceCopyLocalPaths->WithMetadataValue('OriginalProjectReferenceItemSpec', '$(CurrentReference)'))" />
<PdbFiles Include="%(AllItems.Identity)" Condition="@(AllItems->EndsWith('.pdb'))=='true'" />
</ItemGroup>
<ItemGroup>
<TfmSpecificPackageFile Include="@(PdbFiles)" Condition="'%(ProjectReference.NugetIgnore)'!='true'">
<PackagePath>lib/$(TargetFramework)</PackagePath>
</TfmSpecificPackageFile>
</ItemGroup>
</Target>
But there is one issue, the PDB of "main" nuget project is not copied...