what is major difference between dotnet publish and dotnet pack
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.
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.
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.