Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Add dependencies of reference projects to NuGet package

$
0
0

I'm using dotnet pack command for creating a NuGet package for the following scenario:

The projects structure:

Project B|----> Project AProject A|----> SomePackage

I want to create a single NuGet package the contains ProjectB.dll, ProjectA.dll, and SomePackage as NuGet package dependency.

In order to include ProjectA.dll as part of the NuGet package (and not package dependency), I used the following solution that suggests here.

In ProjectB.csproj:

<ProjectReference Include="ProjectA.csproj" PrivateAssets="all"/><PropertyGroup><TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput></PropertyGroup><Target Name="CopyProjectReferencesToPackage" DependsOnTargets="BuildOnlySettings;ResolveReferences"><ItemGroup><!-- Filter out unnecessary files --><_ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'All'))"/></ItemGroup><!-- Print batches for debug purposes --><Message Text="Batch for .nupkg: ReferenceCopyLocalPaths = @(_ReferenceCopyLocalPaths), ReferenceCopyLocalPaths.DestinationSubDirectory = %(_ReferenceCopyLocalPaths.DestinationSubDirectory) Filename = %(_ReferenceCopyLocalPaths.Filename) Extension = %(_ReferenceCopyLocalPaths.Extension)" Importance="High" Condition="'@(_ReferenceCopyLocalPaths)' != ''" /><ItemGroup><!-- Add file to package with consideration of sub folder. If empty, the root folder is chosen. --><BuildOutputInPackage Include="@(_ReferenceCopyLocalPaths)" TargetPath="%(_ReferenceCopyLocalPaths.DestinationSubDirectory)"/></ItemGroup></Target>

The issue:

When I run dotnet pack ProjectB.csproj I'm getting a single package the contains ProjectA.dll and Project B.dll, but without a dependency to SomePackage.

The question:How do I add the dependency to SomePackage to ProjectB NuGet package?

Possible solutions:

  1. Manually add a package reference from ProjectB to SomePackage.
  2. Create ProjectB.nuspec file and manually add the dependency to SomePakcage.

The disadvantage of the 2 approaches: I will need to add the dependency for every NuGet package that ProjectA use, which is very easy to forget and breakable.


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>