Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include all dependencies using dotnet pack

Tags:

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
like image 533
Marcus Avatar asked Nov 03 '16 07:11

Marcus


People also ask

Does NuGet package include dependencies?

Any time a package is installed or reinstalled, which includes being installed as part of a restore process, NuGet also installs any additional packages on which that first package depends. Those immediate dependencies might then also have dependencies on their own, which can continue to an arbitrary depth.

Does dotnet pack also build?

By default, dotnet pack builds the project first. If you wish to avoid this behavior, pass the --no-build option. This option is often useful in Continuous Integration (CI) build scenarios where you know the code was previously built.

How do I update Visual Studio dependencies?

In VS IDE: Right-click project name in Solution Explorer => Manage Nuget Packages , in Updates lab you can choose Select all packages and Update Button.

What does dotnet add package do?

Description. The dotnet add package command provides a convenient option to add or update a package reference in a project file. When you run the command, there's a compatibility check to ensure the package is compatible with the frameworks in the project.


1 Answers

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).

like image 187
3 revs Avatar answered Sep 20 '22 21:09

3 revs