include file for each target framework in nuget

195 Views Asked by At

I have a project (SDK style) with several target frameworks:

<PropertyGroup>
    <TargetFrameworks>net48;netcoreapp3.1;net5.0-windows;net6.0-windows</TargetFrameworks>
</PropertyGroup>

When I build it, a pdb file is generated for each target framework. I want to include these pdb files in the nuget next to their corresponding dll (so, in \lib\targetFramework\).

I am able to do it for one specific framework:

<ItemGroup>
    <Content Include="bin\$(Configuration)\net48\*.pdb" Pack="true" PackagePath="lib\net48" />
</ItemGroup>

How can I specify this for all TargetFrameworks without hard-coding?


I can do it generically if I have the collection of all TargetFrameworks transformed in a certain way:

<ItemGroup>
  <!-- hard-coded collection -->
  <PDBFile Include="bin\$(Configuration)\net48\$(AssemblyName).pdb">
    <NugetFramework>net48</NugetFramework>
  </PDBFile>
  <PDBFile Include="bin\$(Configuration)\netcoreapp3.1\$(AssemblyName).pdb">
    <NugetFramework>netcoreapp3.1</NugetFramework>
  </PDBFile>
  <PDBFile Include="bin\$(Configuration)\net5.0-windows\$(AssemblyName).pdb">
    <NugetFramework>net5.0-windows7.0</NugetFramework>
  </PDBFile>
  <PDBFile Include="bin\$(Configuration)\net6.0-windows\$(AssemblyName).pdb">
    <NugetFramework>net6.0-windows7.0</NugetFramework>
  </PDBFile>

  <!-- generic usage of the collection -->
  <Content Include="@(PDBFile)" Pack="true" PackagePath="lib\%(NugetFramework)"/>
</ItemGroup>

But I still don't know how to define the PDBFile collection in a less hard-coded way...

0

There are 0 best solutions below