1(1)                                  .NET                                  (1)
2
3
4

dotnet pack

6       This article applies to: ✔️ .NET Core 2.x SDK and later versions
7

NAME

9       dotnet pack - Packs the code into a NuGet package.
10

SYNOPSIS

12              dotnet pack [<PROJECT>|<SOLUTION>] [-c|--configuration <CONFIGURATION>]
13                  [--force] [--include-source] [--include-symbols] [--interactive]
14                  [--no-build] [--no-dependencies] [--no-restore] [--nologo]
15                  [-o|--output <OUTPUT_DIRECTORY>] [--runtime <RUNTIME_IDENTIFIER>]
16                  [-s|--serviceable] [-v|--verbosity <LEVEL>]
17                  [--version-suffix <VERSION_SUFFIX>]
18
19              dotnet pack -h|--help
20

DESCRIPTION

22       The  dotnet pack command builds the project and creates NuGet packages.
23       The result of this command is a NuGet package (that is, a .nupkg file).
24
25       If you want to generate a package that contains the debug symbols,  you
26       have two options available:
27
28       • --include-symbols - it creates the symbols package.
29
30       • --include-source  -  it creates the symbols package with a src folder
31         inside containing the source files.
32
33       NuGet dependencies of the packed project are added to the .nuspec file,
34       so  they’re  properly  resolved  when the package is installed.  If the
35       packed project has references to other projects, the other projects are
36       not  included  in  the package.  Currently, you must have a package per
37       project if you have project-to-project dependencies.
38
39       By default, dotnet pack builds the project first.  If you wish to avoid
40       this behavior, pass the --no-build option.  This option is often useful
41       in Continuous Integration (CI) build scenarios where you know the  code
42       was previously built.
43
44              [!NOTE]  In  some cases, the implicit build cannot be performed.
45              This can occur when GeneratePackageOnBuild is set,  to  avoid  a
46              cyclic dependency between build and pack targets.  The build can
47              also fail if there is a locked file or other issue.
48
49       You can provide MSBuild properties to the dotnet pack command  for  the
50       packing  process.   For more information, see NuGet pack target proper‐
51       ties and the MSBuild  Command-Line  Reference.   The  Examples  section
52       shows  how  to use the MSBuild -p switch for a couple of different sce‐
53       narios.
54
55       Web projects aren’t packable by default.  To override the  default  be‐
56       havior, add the following property to your .csproj file:
57
58              <PropertyGroup>
59                 <IsPackable>true</IsPackable>
60              </PropertyGroup>
61
62   Implicit restore
63       You don’t have to run dotnet restore because it’s run implicitly by all
64       commands that require a restore to occur, such as  dotnet  new,  dotnet
65       build,  dotnet  run,  dotnet test, dotnet publish, and dotnet pack.  To
66       disable implicit restore, use the --no-restore option.
67
68       The dotnet restore command is still useful in certain  scenarios  where
69       explicitly restoring makes sense, such as continuous integration builds
70       in Azure DevOps Services or in build systems that  need  to  explicitly
71       control when the restore occurs.
72
73       For information about how to manage NuGet feeds, see the dotnet restore
74       documentation.
75
76       This command supports the dotnet restore options  when  passed  in  the
77       long form (for example, --source).  Short form options, such as -s, are
78       not supported.
79
80   Workload manifest downloads
81       When you run this command,  it  initiates  an  asynchronous  background
82       download  of  advertising  manifests for workloads.  If the download is
83       still running when this command finishes, the download is stopped.  For
84       more information, see Advertising manifests.
85
86   Arguments
87       PROJECT | SOLUTION
88
89       The  project  or  solution  to  pack.   It’s either a path to a csproj,
90       vbproj, or fsproj file, or to a solution file  or  directory.   If  not
91       specified,  the command searches the current directory for a project or
92       solution file.
93

OPTIONS

95-c|--configuration <CONFIGURATION>
96
97         Defines the build configuration.  The default for  most  projects  is
98         Debug,  but you can override the build configuration settings in your
99         project.
100
101--force
102
103         Forces all dependencies to be resolved even if the last  restore  was
104         successful.   Specifying  this  flag  is  the  same  as  deleting the
105         project.assets.json file.
106
107-?|-h|--help
108
109         Prints out a description of how to use the command.
110
111--include-source
112
113         Includes the debug symbols NuGet packages in addition to the  regular
114         NuGet  packages  in  the output directory.  The sources files are in‐
115         cluded in the src folder within the symbols package.
116
117--include-symbols
118
119         Includes the debug symbols NuGet packages in addition to the  regular
120         NuGet packages in the output directory.
121
122--interactive
123
124         Allows  the  command  to stop and wait for user input or action.  For
125         example, to complete authentication.  Available since .NET  Core  3.0
126         SDK.
127
128--no-build
129
130         Doesn’t  build  the  project before packing.  It also implicitly sets
131         the --no-restore flag.
132
133--no-dependencies
134
135         Ignores project-to-project references  and  only  restores  the  root
136         project.
137
138--no-restore
139
140         Doesn’t execute an implicit restore when running the command.
141
142--nologo
143
144         Doesn’t  display the startup banner or the copyright message.  Avail‐
145         able since .NET Core 3.0 SDK.
146
147-o|--output <OUTPUT_DIRECTORY>
148
149         Places the built packages in the directory specified.
150
151--runtime <RUNTIME_IDENTIFIER>
152
153         Specifies the target runtime to restore packages for.  For a list  of
154         Runtime Identifiers (RIDs), see the RID catalog.
155
156-s|--serviceable
157
158         Sets  the serviceable flag in the package.  For more information, see
159         .NET Blog: .NET Framework 4.5.1 Supports Microsoft  Security  Updates
160         for .NET NuGet Libraries (https://aka.ms/nupkgservicing).
161
162-v|--verbosity <LEVEL>
163
164         Sets the verbosity level of the command.  Allowed values are q[uiet],
165         m[inimal], n[ormal], d[etailed], and diag[nostic].  For more informa‐
166         tion, see <xref:Microsoft.Build.Framework.LoggerVerbosity>.
167
168--version-suffix <VERSION_SUFFIX>
169
170         Defines the value for the VersionSuffix MSBuild property.  The effect
171         of this property on the package version depends on the values of  the
172         Version  and  VersionPrefix properties, as shown in the following ta‐
173         ble:
174
175         Properties with values       Package version
176         ─────────────────────────────────────────────────────
177         None                         1.0.0
178         Version                      $(Version)
179         VersionPrefix only           $(VersionPrefix)
180         VersionSuffix only           1.0.0-$(VersionSuffix)
181         VersionPrefix and Version‐   $(VersionPrefix)-$(Ver‐
182         Suffix                       sionSuffix)
183
184         If you want to use --version-suffix, specify  VersionPrefix  and  not
185         Version  in the project file.  For example, if VersionPrefix is 0.1.2
186         and you pass --version-suffix rc.1 to dotnet pack, the  package  ver‐
187         sion will be 0.1.2-rc.1.
188
189         If  Version has a value and you pass --version-suffix to dotnet pack,
190         the value specified for --version-suffix is ignored.
191

EXAMPLES

193       • Pack the project in the current directory:
194
195                dotnet pack
196
197       • Pack the app1 project:
198
199                dotnet pack ~/projects/app1/project.csproj
200
201       • Pack the project in the current directory  and  place  the  resulting
202         packages into the nupkgs folder:
203
204                dotnet pack --output nupkgs
205
206       • Pack  the project in the current directory into the nupkgs folder and
207         skip the build step:
208
209                dotnet pack --no-build --output nupkgs
210
211       • With the project’s version suffix configured as <VersionSuffix>$(Ver‐
212         sionSuffix)</VersionSuffix>  in  the  .csproj  file, pack the current
213         project and update the resulting package version with the given  suf‐
214         fix:
215
216                dotnet pack --version-suffix "ci-1234"
217
218       • Set  the  package  version  to  2.1.0 with the PackageVersion MSBuild
219         property:
220
221                dotnet pack -p:PackageVersion=2.1.0
222
223       • Pack the project for a specific target framework:
224
225                dotnet pack -p:TargetFrameworks=net45
226
227       • Pack the project and use a specific runtime (Windows 10) for the  re‐
228         store operation:
229
230                dotnet pack --runtime win10-x64
231
232       • Pack the project using a .nuspec file:
233
234                dotnet pack ~/projects/app1/project.csproj -p:NuspecFile=~/projects/app1/project.nuspec -p:NuspecBasePath=~/projects/app1/nuget
235
236         For information about how to use NuspecFile, NuspecBasePath, and Nus‐
237         pecProperties, see the following resources:
238
239         • Packing using a .nuspec
240
241         • Advanced extension points to create customized package
242
243         • Global properties
244
245
246
247                                                                           (1)
Impressum