19

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.

belwood
  • 2,444
  • 10
  • 32
  • 38
Lost
  • 8,195
  • 27
  • 95
  • 163

3 Answers3

18

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.

abatishchev
  • 92,232
  • 78
  • 284
  • 421
t0mm13b
  • 32,846
  • 7
  • 71
  • 106
  • jsut to clarify `"self-contained"` here implies inclusion of the executable. That's the part which actually makes it `copy-pastable` and executable just by `copy-paste`.Is that correct? – Lost May 22 '17 at 18:59
  • 1
    Correct, *compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files to a directory* – t0mm13b May 22 '17 at 19:02
6

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.

Pang
  • 8,605
  • 144
  • 77
  • 113
Martin Ullrich
  • 78,211
  • 20
  • 211
  • 189
1

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.

Pang
  • 8,605
  • 144
  • 77
  • 113
Udit Gandhi
  • 198
  • 2
  • 5