There are different ways to do it and they depend on what you're trying to achieve.
From .NET application publishing overview
Type |
Command |
framework-dependent executable for the current platform. |
dotnet publish |
framework-dependent executable for a specific platform. |
dotnet publish -r --self-contained false |
framework-dependent cross-platform binary. |
dotnet publish |
self-contained executable. |
dotnet publish -r |
From the Examples section:
Publish an app cross-platform framework-dependent. A Linux 64-bit executable is created along with the dll file. This command doesn't work with .NET Core SDK 2.1.
dotnet publish -r linux-x64 --self-contained false
You may be interested in Single-file deployment and executable:
Bundling all application-dependent files into a single binary provides an application developer with the attractive option to deploy and distribute the application as a single file. Single-file deployment is available for both the framework-dependent deployment model and self-contained applications.