I have two class library projects (ClassLibA and ClassLibB) in my solution, and I would like to package them together into a single NuGet package, rather than creating separate packages for each library. The goal is to include both libraries in one .nupkg file, so when someone installs this package, they can reference both ClassLibA and ClassLibB.
Here's the setup I currently have:
ClassLibA and ClassLibB are both .NET Framework 4.7.2 projects. I’ve created a third project (MergerClassLin) and added project references to ClassLibA and ClassLibB in it. I want to ensure that when I build the MergerClassLin project, both ClassLibA and ClassLibB are included in the resulting NuGet package. I’ve tried using ProjectReference in the .csproj of MergerClassLin, but when I generate the NuGet package, it only includes the MergerClassLin.dll and doesn’t package ClassLibA and ClassLibB.
Here's what I’ve done so far in MergerClassLin.csproj:
xml Copy code
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeReferencedProjects>true</IncludeReferencedProjects>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ClassLibA\ClassLibA.csproj">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</ProjectReference>
<ProjectReference Include="..\ClassLibB\ClassLibB.csproj">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</ProjectReference>
</ItemGroup>
The NuGet package builds, but it only contains MergerClassLin.dll. I want to include both ClassLibA.dll and ClassLibB.dll in the NuGet package as well.
What’s the best way to combine multiple class libraries into a single NuGet package? Is there something I’m missing in the .csproj configuration or packaging process?
Any help would be appreciated!
You are missing some lines that should go in the .csproj file:
<Target Name="CopyLibraries" AfterTargets="Build">
<Copy SourceFiles="@(ProjectReference->'%(TargetDir)%(TargetName).dll')" DestinationFolder="$(OutputPath)" />
</Target>
<ItemGroup>
<None Include="$(OutputPath)\ClassLibA.dll" Pack="true" PackagePath="lib\net472\" />
<None Include="$(OutputPath)\ClassLibB.dll" Pack="true" PackagePath="lib\net472\" />
</ItemGroup>
these lines are use for:
Otherwise, you should follow the manual way explained in the comment above.