dotnet-pack(1)
okay so bestie, you've found the manual page for dotnet-pack(1) π β that's the .NET Documentation one, and yes, this article applies to: βοΈ .NET 6 SDK and later versions. Strap in, she's a long one. πΈ
π NAME π
dotnet-pack β Packs the code into a NuGet package. that's it. that's the vibe. π
β¨ SYNOPSIS β¨
dotnet pack [<PROJECT>|<SOLUTION>]
[--artifacts-path <ARTIFACTS_DIR>] [-c|--configuration <CONFIGURATION>]
[--disable-build-servers] [--force] [--include-source] [--include-symbols]
[--interactive] [--no-build] [--no-dependencies] [--no-restore] [--nologo]
[-o|--output <OUTPUT_DIRECTORY>] [--runtime <RUNTIME_IDENTIFIER>]
[-s|--serviceable] [--tl:[auto|on|off]] [-v|--verbosity <LEVEL>]
[--version-suffix <VERSION_SUFFIX>]
dotnet pack -h|--help
π DESCRIPTION π
okay so the dotnet pack command builds the project and creates NuGet packages. what you get out of it is a NuGet package β that is, a .nupkg file. periodt. π
if you want to generate a package that has the debug symbols in it too, you've got two options, bestie:
--include-symbolsβ it creates the symbols package.--include-sourceβ it creates the symbols package with asrcfolder inside containing the source files.
NuGet dependencies of the packed project get added to the .nuspec file, so they're properly resolved when the package gets installed. but listen β if the packed project has references to other projects, those other projects aren't included in the package. π Currently, you must have a package per project if you have project-to-project dependencies.
By default, dotnet pack builds the project first. if you wish to avoid this behavior, pass the --no-build option. this option is often useful in Continuous Integration (CI) build scenarios where you know the code was previously built. β¨
π In some cases, the implicit build cannot be performed. This can occur when GeneratePackageOnBuild is set, to avoid a cyclic dependency between build and pack targets. The build can also fail if there is a locked file or other issue.
you can provide MSBuild properties to the dotnet pack command for the packing process. for more information, see NuGet pack target properties and the MSBuild Command-Line Reference. the Examples section shows how to use the MSBuild -p switch for a couple of different scenarios. π
β οΈ Web projects aren't packable. (not me finding that out the hard way π)
π¦ Implicit restore π¦
you don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur β like dotnet new, dotnet build, dotnet run, dotnet test, dotnet publish, and dotnet pack. to disable implicit restore, use the --no-restore option. π«Ά
the dotnet restore command is still useful in certain scenarios where explicitly restoring makes sense, such as continuous integration builds in Azure DevOps Services or in build systems that need to explicitly control when the restore occurs.
for info about how to manage NuGet feeds, see the dotnet restore documentation.
π‘ This command supports thedotnet restoreoptions when passed in the long form (for example,--source). Short form options, such as-s, are not supported. iykyk.
π§ Workload manifest downloads π§
when you run this command, it initiates an asynchronous background download of advertising manifests for workloads. if the download is still running when this command finishes, the download is stopped. for more information, see Advertising manifests.
πΈ ARGUMENTS πΈ
PROJECT | SOLUTIONβ the project or solution to pack. it's either a path to acsproj,vbproj, orfsprojfile, or to a solution file or directory. if not specified, the command searches the current directory for a project or solution file. π
π OPTIONS π
--artifacts-path <ARTIFACTS_DIR>β all build output files from the executed command will go in subfolders under the specified path, separated by project. for more information see Artifacts Output Layout. available since .NET 8 SDK. β¨-c|--configuration <CONFIGURATION>β defines the build configuration. if you're developing with the .NET 8 SDK or a later version, the command uses theReleaseconfiguration by default for projects whoseTargetFrameworkis set tonet8.0or a later version. the default build configuration isDebugfor earlier versions of the SDK and for earlier target frameworks. you can override the default in project settings or by using this option. for more info, seedotnet publishuses Release configuration anddotnet packuses Release configuration. π--disable-build-serversβ forces the command to ignore any persistent build servers. this option provides a consistent way to disable all use of build caching, which forces a build from scratch. a build that doesn't rely on caches is useful when the caches might be corrupted or incorrect for some reason. available since .NET 7 SDK. π₯--forceβ forces all dependencies to be resolved even if the last restore was successful. specifying this flag is the same as deleting theproject.assets.jsonfile. π--include-sourceβ includes the debug symbols NuGet packages in addition to the regular NuGet packages in the output directory. the sources files are included in thesrcfolder within the symbols package.--include-symbolsβ includes the debug symbols NuGet packages in addition to the regular NuGet packages in the output directory.--interactiveβ allows the command to stop and wait for user input or action. for example, to complete authentication. π--no-buildβ doesn't build the project before packing. it also implicitly sets the--no-restoreflag.--no-dependenciesβ ignores project-to-project references and only restores the root project.--no-restoreβ doesn't execute an implicit restore when running the command.--nologoβ doesn't display the startup banner or the copyright message. (lowkey the move for clean CI logs π§Ό)-o|--output <OUTPUT_DIRECTORY>β places the built packages in the directory specified.- .NET 7.0.200 SDK β in the 7.0.200 SDK, if you specify the
--outputoption when running this command on a solution, the CLI will emit an error. this is a regression and was fixed in 7.0.201 and later versions of the .NET SDK. π
- .NET 7.0.200 SDK β in the 7.0.200 SDK, if you specify the
--runtime <RUNTIME_IDENTIFIER>β specifies the target runtime to restore packages for. for a list of Runtime Identifiers (RIDs), see the RID catalog.-s|--serviceableβ sets the serviceable flag in the package. for more information, see .NET Blog: .NET Framework 4.5.1 Supports Microsoft Security Updates for .NET NuGet Libraries (https://aka.ms/nupkgservicing). π--tl:[auto|on|off]β specifies whether Terminal Logger should be used for the build output. the default isauto, which first verifies the environment before enabling terminal logging. the environment check verifies that the terminal is capable of using modern output features and isn't using a redirected standard output before enabling the new logger.onskips the environment check and enables terminal logging.offskips the environment check and uses the default console logger.
Terminal Logger shows you the restore phase followed by the build phase. during each phase, the currently building projects appear at the bottom of the terminal. each project that's building outputs both the MSBuild target currently being built and the amount of time spent on that target. you can search this information to learn more about the build. when a project is finished building, a single "build completed" section is written that captures:
- The name of the built project.
- The target framework (if multi-targeted).
- The status of that build.
- The primary output of that build (which is hyperlinked).
- Any diagnostics generated for that project.
π This option is available starting in .NET 8.
-v|--verbosity <LEVEL>β sets the verbosity level of the command. allowed values areq[uiet],m[inimal],n[ormal],d[etailed], anddiag[nostic]. for more information, see<xref:Microsoft.Build.Framework.LoggerVerbosity>. π--version-suffix <VERSION_SUFFIX>β defines the value for theVersionSuffixMSBuild property. the effect of this property on the package version depends on the values of theVersionandVersionPrefixproperties, like this:- no properties with values β package version
1.0.0 Versionβ package version$(Version)VersionPrefixonly β package version$(VersionPrefix)VersionSuffixonly β package version1.0.0-$(VersionSuffix)VersionPrefixandVersionSuffixβ package version$(VersionPrefix)-$(VersionSuffix)
- no properties with values β package version
if you want to use --version-suffix, specify VersionPrefix and not Version in the project file. for example, if VersionPrefix is 0.1.2 and you pass --version-suffix rc.1 to dotnet pack, the package version will be 0.1.2-rc.1. β¨
π IfVersionhas a value and you pass--version-suffixtodotnet pack, the value specified for--version-suffixis ignored.
-?|-h|--helpβ prints out a description of how to use the command. π«Ά
β¨ EXAMPLES β¨
okay bestie this is the part where it all clicks, like the vibes are immaculate here π every single one of these is copy-paste-able, no cap.
π the classics
- Pack the project in the current directory:
dotnet pack
literally the bare minimum and she still ate π₯
- Pack the
app1project:
dotnet pack ~/projects/app1/project.csproj
point at the project file directly when you're not standing in it, iykyk π«Ά
- Pack the project in the current directory and place the resulting packages into the
nupkgsfolder:
dotnet pack --output nupkgs
- Pack the project in the current directory into the
nupkgsfolder and skip the build step:
dotnet pack --no-build --output nupkgs
no build, just vibes β¨
π¦ versioning shenanigans
- With the project's version suffix configured as
<VersionSuffix>$(VersionSuffix)</VersionSuffix>in the.csprojfile, pack the current project and update the resulting package version with the given suffix:
dotnet pack --version-suffix "ci-1234"
- Set the package version to
2.1.0with thePackageVersionMSBuild property:
dotnet pack -p:PackageVersion=2.1.0
πΈ targeting & runtime things
- Pack the project for a specific target framework:
dotnet pack -p:TargetFrameworks=net45
- Pack the project and use a specific runtime (Windows) for the restore operation:
dotnet pack --runtime win-x64
π§ the nuspec era
- Pack the project using a
.nuspecfile:
dotnet pack ~/projects/app1/project.csproj -p:NuspecFile=~/projects/app1/project.nuspec -p:NuspecBasePath=~/projects/app1/nuget
For information about how to use NuspecFile, NuspecBasePath, and NuspecProperties, see the following resources:
- Packing using a
.nuspec - Advanced extension points to create customized package
- Global properties
fr fr go read those three, they're the main character energy of nuspec packing π
and that's the whole page bestie!! π this one came from the dotnet-pack(1) man page, dated 2025-10-30 β go forth and pack, you absolute icon πβ¨π¦
π¦ where this page comes from
- alpine 3.24: dotnet-doc 10.0.303-r2 Β· MIT
- centos-stream 10: dotnet-host 11.0.0~rc.2.26504.105-0.10.el10 Β· 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
- centos-stream 9: dotnet-host 11.0.0~rc.2.26504.105-0.11.el9 Β· 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
- fedora 43: dotnet-host 10.0.12-1.fc43
- fedora 43: dotnet-host 11.0.0~rc.1.26425.128-0.10.fc43 Β· 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
- fedora 44: dotnet-host 10.0.12-1.fc44
- fedora 44: dotnet-host 10.0.4-1.fc44 Β· 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
- fedora 44: dotnet-host 11.0.0~rc.1.26425.128-0.12.fc44 Β· 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
- nixpkgs unstable: dotnet-vmr 11.0.0-rc.3
- ubuntu noble: dotnet-host-10.0 10.0.12-0ubuntu1~24.04.1
- ubuntu questing: dotnet-host-10.0 10.0.9-0ubuntu1~25.10.1
- ubuntu resolute: dotnet-host-10.0 10.0.12-0ubuntu1~26.04.1
- ubuntu resolute: dotnet-host-10.0 10.0.5-0ubuntu1 Β· MIT
- ubuntu stonking: dotnet-host-10.0 10.0.12-0ubuntu2 Β· MIT
- ubuntu stonking: dotnet-host-11.0 11.0.0~rc1-0ubuntu1 Β· MIT
- ubuntu stonking: dotnet-host-11.0 11.0.0~rc3-0ubuntu1~26.10.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms