Publish a .NET Application
- 3 minutes to read
This article describes how to deploy a .NET application. The following deployment modes are available:
- Creates an application that includes all its dependencies and the .NET runtime. Users can run this application on a machine that does not have the .NET runtime installed.
- Creates an application that does not include the .NET runtime. Users should install the .NET runtime separately to run this application.
See the following topic for more information on application deployment modes: .NET Application Publishing Overview.
Deploy with CLI Tools
Use the dotnet publish command to publish a .NET application from the command line.
# Framework-dependent deployment # for the current platform dotnet publish -c Release # Framework-dependent deployment # for a specific platform dotnet publish -c Release -r <RID> --self-contained false # Self-contained deployment dotnet publish -c Release -r <RID> --self-contained true
-r <RID> option specifies the target platform where the application should run: win-x86, win-x64, linux-x64, osx-x64, and so on.
Deploy with Visual Studio
Right-click the project’s name in the Solution Explorer and select Publish.
In the invoked dialog, select Folder as the publish target and click Next.
On the Specific target tab, select Folder and click Next.
On the Location tab, specify the path to the target folder and click Finish.
Click Publish to publish your application to the selected folder.
If you need to modify your publish profile, click Show all settings and change project configuration in the Profile settings dialog.
You can pack your application and its dependencies (including the .NET runtime) into a single executable as described below.
Method 1 (Edit the project file)
Runtime Identifier and set the
PublishSingleFile option to true in your project file.
<PropertyGroup> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <PublishSingleFile>true</PublishSingleFile> </PropertyGroup>
Method 2 (Use the command line)
dotnet publish command with the following parameters:
dotnet publish -r win-x64 /p:PublishSingleFile=true
Ready to Run Images
You can compile your application in a ReadyToRun (R2R) format to improve the application startup time.
To publish your project as ReadyToRun, set the
PublishReadyToRun option to true in your project file:
<PropertyGroup> <PublishReadyToRun>true</PublishReadyToRun> </PropertyGroup>
If you enable the ReadyToRun option, the application size increases because R2R binaries contain both intermediate language and native code (similar to what the just-in-time compiler produces). This native code reduces the JIT compiler workload during application startup.
R2R format is only available when you publish an app that targets a specific runtime environment (such as Windows x64 or Linux x64).