Make nuget package to include DLLs from referenced projects

nuget

Let's assume we have two projects: ProjectA and ProjectB. ProjectA references ProjectB. When we create a nuget package for ProjectA, by default the package is asking for a nuget package of ProjectB. What if we don't want to create a package for ProjectB, yet we want the referenced files to be included in our nuget package for ProjectA?

Edit the .csproj for Project A and set the following:



 <ItemGroup>
   <ProjectReference Include="..\ProjectB\ProjectB.csproj">
     <PrivateAssets>All</PrivateAssets>
   </ProjectReference>
   <Content Include="$(OutputPath)\ProjectB.dll">
     <Pack>true</Pack>
     <PackagePath>lib\$(TargetFramework)</PackagePath>
   </Content>
 </ItemGroup>
  

The "PrivateAssets" section means that the package for ProjectB should not ask dependencies. The content/include section shows which files to include in the package - notice, the files are put in the lib folder.

Post a Comment

Previous Post Next Post