1dotnet-pack(1)                .NET Documentation                dotnet-pack(1)
2
3
4

dotnet pack

6       This article applies to: ✔️ .NET Core 3.1 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              In some cases, the implicit build cannot be performed.  This can
45              occur when GeneratePackageOnBuild is set, to avoid a cyclic  de‐
46              pendency  between  build  and  pack targets.  The build can also
47              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.
56
57   Implicit restore
58       You don’t have to run dotnet restore because it’s run implicitly by all
59       commands  that  require  a restore to occur, such as dotnet new, dotnet
60       build, dotnet run, dotnet test, dotnet publish, and  dotnet  pack.   To
61       disable implicit restore, use the --no-restore option.
62
63       The  dotnet  restore command is still useful in certain scenarios where
64       explicitly restoring makes sense, such as continuous integration builds
65       in  Azure  DevOps  Services or in build systems that need to explicitly
66       control when the restore occurs.
67
68       For information about how to manage NuGet feeds, see the dotnet restore
69       documentation.
70
71       This  command  supports  the  dotnet restore options when passed in the
72       long form (for example, --source).  Short form options, such as -s, are
73       not supported.
74
75   Workload manifest downloads
76       When  you  run  this  command,  it initiates an asynchronous background
77       download of advertising manifests for workloads.  If  the  download  is
78       still running when this command finishes, the download is stopped.  For
79       more information, see Advertising manifests.
80

ARGUMENTS

82       PROJECT | SOLUTION
83
84       The project or solution to pack.  It’s  either  a  path  to  a  csproj,
85       vbproj,  or  fsproj  file,  or to a solution file or directory.  If not
86       specified, the command searches the current directory for a project  or
87       solution file.
88

OPTIONS

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

EXAMPLES

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