问题
Is there any way to force dotnet pack
to include all referenced assemblies (all dependencies in project.json)?
I believe this is related:
- https://github.com/dotnet/cli/issues/1290
- https://github.com/dotnet/cli/issues/3959
回答1:
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 by editing your .csproj to include the following (full credit to @teroneko who came up with this on GitHub):
<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>
Then all you do is mark the depended-upon project reference(s) in your .csproj with PrivateAssets="all"
, and it Just Works(tm).
回答2:
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
回答3:
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...
回答4:
I hope this will help you.
nuget pack yournuspecfile.nuspec -properties Configuration=Release -IncludeReferencedProjects
or your command whatever.
来源:https://stackoverflow.com/questions/40396161/include-all-dependencies-using-dotnet-pack