mark
mark

Reputation: 62712

How to pack .NET Core projects recursively without running pack on the entire solution?

I have a solution of a hundred plus .NET Core projects. Not all of them needs to be packed, but only those which are transitive dependencies of a few special projects.

However, when I run dotnet pack it attempts to pack all kinds of projects that it should not and there are errors here and there. I would like instead to run pack on the special projects only in a recursive fashion, so that only them and their transitive dependencies (project references, of course) are packed.

I figured I can implement it by scripting around the dotnet list reference command, but it does not sound right. There must be a better way to do it.

EDIT 1

The solution must work on the command line where we have dotnet and msbuild and possibly nuget, but no VS IDE.

Upvotes: 1

Views: 705

Answers (1)

Dmitry
Dmitry

Reputation: 16795

You can modify your project settings to generate *.nupkg file during dotnet build, without explicit dotnet pack call. And as soon as dependencies get builded automatically when "parent" project builds - you will receive nuget packages prepared for all dependencies too when you run dotnet build for "parent" project only.

For each project that should produce nuget package add this lines into csproj file:

<PropertyGroup>
  <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

Or, instead, you may enable checkbox "Generate NuGet package on build" from Visual Studio, in project properties ("Package" tab) - this will add same line into project file.

Upvotes: 2

Related Questions