Reputation: 13575
What is the major difference between dotnet pack
and publish
?
From Microsoft's description, my understanding is that pack
creates a package while publish
creates package + DLL.
Is this correct?
If so, why not just always use publish
and not use the DLL file if it is not needed.
Upvotes: 33
Views: 14636
Reputation: 357
Basically, when we use the pack
command, it creates a package; when we use the publish
command, it creates a folder that can be copied and executed from anywhere.
What makes pack
command unique is that the package gets updated to the nuget server without uploading its dependencies. Its dependencies are updated in the project which fetches the package when we run dotnet restore
. This is not with the case of dotnet publish
, as it contains third-party dependencies packed in the bundle.
Upvotes: 4
Reputation: 100581
Adding to the answer by @t0mm13b:
dotnet pack
: The output is a package that is meant to be reused by other projects.
dotnet publish
: The output is mean to be deployed / "shipped" - it is not a single "package file" but a directory with all the project's output.
Upvotes: 13
Reputation: 34592
dotnet pack
- Produces a NuGet package of your code.
That is the key difference - this will enable to publish to http://nuget.org, or to a nuget server that can be pulled down by other developers, or even for use with Octopus Deploy.
dotnet publish
- Produces a .NET framework-dependent or self-contained application.
Keyword is "self-contained", a installer perhaps, or a folder that can be deployed by copying/pasting between hosts.
Upvotes: 31