简体   繁体   English

将项目引用的 PDB 文件包含到 nuget 包中

[英]Including project referenced PDB files into nuget package

I'm trying to include PDB files of project references into Nuget package, by using dotnet pack command.我正在尝试使用 dotnet pack 命令将项目引用的 PDB 文件包含到 Nuget 包中。

I've found solution to include project referenced DLL files into nuget package.我找到了将项目引用的 DLL 文件包含到 nuget 包中的解决方案。 This needs adding some code to .csproj file.这需要向 .csproj 文件添加一些代码。 I've also tried to make it work with .pdb files, but this doesn't work.我也试图让它与 .pdb 文件一起工作,但这不起作用。

This code copy only *.dll files to nuget.此代码仅将 *.dll 文件复制到 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.这是我尝试过的,但 *.pdb 文件在 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:我已经资助了复制引用的 PDB 的解决方案 - 只需将此行添加到您的 .csproj 文件中:

<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...但是有一个问题,"main" nuget 项目的 PDB 没有被复制......

The configuration below is actually a fix for your initial idea to transform a DLL path to a PDB path.下面的配置实际上是对您将 DLL 路径转换为 ​​PDB 路径的最初想法的修复。 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 ). PDB 文件未出现在生成的 nuget 包中的原因是输出文件在后续过程中被进一步过滤(请参阅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.它生成一个包含编译项目的 DLL/PDB 和引用项目的 DLL/PDB 的包。

<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>

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.这包括包中的 *.pdb 文件。 You can read more about include symbols Here您可以在此处阅读有关包含符号的更多信息

Edit: My answer doesn't fulfill the question requirement.编辑:我的回答不符合问题要求。 Please read the comments to this message.请阅读此消息的评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM