This article applies to: ✔️ .NET Core 2.1 SDK and later versions
dotnet publish - Publishes the application and its dependencies to a folder for deployment to a hosting system.
dotnet publish [<PROJECT>|<SOLUTION>] [-c|--configuration] [-f|--framework] [--force] [--interactive] [--manifest] [--no-build] [--no-dependencies] [--no-restore] [--nologo] [-o|--output] [-r|--runtime] [--self-contained] [--no-self-contained] [-v|--verbosity] [--version-suffix] dotnet publish [-h|--help]
dotnet publish compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files to a directory. The output includes the following assets:
- Intermediate Language (IL) code in an assembly with a dll extension.
- A .deps.json file that includes all of the dependencies of the project.
- A .runtimeconfig.json file that specifies the shared runtime that the application expects, as well as other configuration options for the runtime (for example, garbage collection type).
- The application's dependencies, which are copied from the NuGet cache into the output folder.
dotnet publish command's output is ready for deployment to a hosting system (for example, a server, PC, Mac, laptop) for execution. It's the only officially supported way to prepare the application for deployment. Depending on the type of deployment that the project specifies, the hosting system may or may not have the .NET Core shared runtime installed on it.
The project or solution to publish.
PROJECTis the path and filename of a C#, F#, or Visual Basic project file, or the path to a directory that contains a C#, F#, or Visual Basic project file. If the directory is not specified, it defaults to the current directory.
SOLUTIONis the path and filename of a solution file (.sln extension), or the path to a directory that contains a solution file. If the directory is not specified, it defaults to the current directory. Available starting with .NET Core 3.0 SDK.
Defines the build configuration. The default for most projects is
Debug, but you can override the build configuration settings in your project.
Publishes the application for the specified target framework. You must specify the target framework in the project file.
Forces all dependencies to be resolved even if the last restore was successful. Specifying this flag is the same as deleting the project.assets.json file.
Prints out a short help for the command.
--interactiveAvailable starting with .NET Core 3.0 SDK.
Allows the command to stop and wait for user input or action. For example, to complete authentication.
Specifies one or several target manifests to use to trim the set of packages published with the app. The manifest file is part of the output of the
dotnet storecommand. To specify multiple manifests, add a
--manifestoption for each manifest.
Doesn't build the project before publishing. It also implicitly sets the
Ignores project-to-project references and only restores the root project.
--nologoAvailable starting with .NET Core 3.0 SDK.
Doesn't display the startup banner or the copyright message.
Doesn't execute an implicit restore when running the command.
Specifies the path for the output directory. If not specified, it defaults to ./bin/[configuration]/[framework]/publish/ for a runtime-dependent executable and cross-platform binaries. It defaults to ./bin/[configuration]/[framework]/[runtime]/publish/ for a self-contained executable.
If the path is relative, the output directory generated is relative to the project file location, not to the current working directory.
Publishes the .NET Core runtime with your application so the runtime doesn't need to be installed on the target machine. Default is
trueif a runtime identifier is specified. For more information, see .NET Core application publishing and Publish .NET Core apps with the .NET Core CLI.
--no-self-containedAvailable starting with .NET Core 3.0 SDK.
Publishes the application for a given runtime. For a list of Runtime Identifiers (RIDs), see the RID catalog. For more information, see .NET Core application publishing and Publish .NET Core apps with the .NET Core CLI.
Sets the verbosity level of the command. Allowed values are
Defines the version suffix to replace the asterisk (
*) in the version field of the project file.
Create a runtime-dependent cross-platform binary for the project in the current directory:
Starting with .NET Core 3.0 SDK, this example also creates a runtime-dependent executable for the current platform.
Create a self-contained executable for the project in the current directory, for a specific runtime:
dotnet publish --runtime osx.10.11-x64
The RID must be in the project file.
Create a runtime-dependent executable for the project in the current directory, for a specific platform:
dotnet publish --runtime osx.10.11-x64 --self-contained false
The RID must be in the project file. This example applies to .NET Core 3.0 SDK and later versions.
Publish the project in the current directory, for a specific runtime and target framework:
dotnet publish --framework netcoreapp3.1 --runtime osx.10.11-x64
Publish the specified project file:
dotnet publish ~/projects/app1/app1.csproj
Publish the current application but don't restore project-to-project (P2P) references, just the root project during the restore operation:
dotnet publish --no-dependencies