Including project referenced PDB files into nuget package

强颜欢笑 提交于 2020-04-15 04:34:09

问题


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-&gt;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-&gt;WithMetadataValue('OriginalProjectReferenceItemSpec', '$(CurrentReference)'))" />
        <PdbFiles Include="%(AllItems.Identity)" Condition="@(AllItems-&gt;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...


回答1:


The configuration below is actually a fix for your initial idea to transform a DLL path to a PDB path. The reason why PDB files didn't appear in a generated nuget package is that the output files get filtered further down the road (see AllowedOutputExtensionsInPackageBuildOutputFolder). Fortunately, we can customize what extensions should be kept.

See the final configuration below. It generates a package with a DLL/PDB of the compiling project plus DLLs/PDBs of referenced projects.

<PropertyGroup>
  <!--Include Project References output-->
  <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>

  <!--Allow certain extensions-->
  <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
  <ItemGroup>
    <!--Include DLLs of Project References-->
    <BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))"/>

    <!--Include PDBs of Project References-->
    <BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->Replace('.dll', '.pdb'))"/>
  </ItemGroup>
</Target>



回答2:


You can force the command to contains the symbols.

--include-symbols

Final command for example:

dotnet pack -c Debug --include-symbols

This includes your *.pdb file in the package. You can read more about include symbols Here

Edit: My answer doesn't fulfill the question requirement. Please read the comments to this message.



来源:https://stackoverflow.com/questions/54129910/including-project-referenced-pdb-files-into-nuget-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!