Include all dependencies using dotnet pack

前端 未结 4 1180
滥情空心
滥情空心 2021-01-02 00:19

Is there any way to force dotnet pack to include all referenced assemblies (all dependencies in project.json)?

I believe this is related:

相关标签:
4条回答
  • 2021-01-02 00:41

    I hope this will help you.

    nuget pack yournuspecfile.nuspec -properties Configuration=Release -IncludeReferencedProjects

    or your command whatever.

    0 讨论(0)
  • 2021-01-02 00:50

    By design each dependency needs to be dotnet packed separately.

    Some people include dlls from their release folder as files in their package options to work around the design.

    However, creating packages for each individual dependency would result in code that's easier to version, maintain, update etc...

    0 讨论(0)
  • 2021-01-02 01:04

    As of 2020 there is no officially supported way to do this. However various people have come up with ways to achieve it, and the current best way is to install a NuGet package prepared by the amazing Teroneko. Then all you need to do is edit your .csproj to update all your project to be flagged with PrivateAssets="all", as per the package README.


    If you are unable to install the aforementioned NuGet package, you can achieve the same effect by editing by editing your .csproj to include the following (once again, this was discovered by Teroneko - it's essentially what the NuGet package he created does):

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

    As with the package, you then mark the depended-upon project reference(s) in your .csproj with PrivateAssets="all", and it Just Works(tm).

    0 讨论(0)
  • 2021-01-02 01:05

    I was looking for this answer and was annoyed when I couldn't find an obvious one. The solution that worked best for me was to create a nuspec, add the list of DLLs I wanted in the nupkg to that spec and then build with dotnet pack. I created an easy sample and readme here - nuget sample app

    0 讨论(0)
提交回复
热议问题