Skip to main content

Publish a .NET Application

  • 3 minutes to read

This article describes how to deploy a .NET application. The following deployment modes are available:

Self-Contained
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.
Framework-Dependent
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

The -r <RID> option specifies the target platform where the application should run: win-x86, win-x64, linux-x64, osx-x64, and so on.

See the .NET Runtime Identifier catalog.

Deploy with Visual Studio

  1. Right-click the project’s name in the Solution Explorer and select Publish.

    Publish an app in Visual Studio

  2. In the invoked dialog, select Folder as the publish target and click Next.

    Select Folder as the publish target

  3. On the Specific target tab, select Folder and click Next.

    Select Folder on the Specific target tab

  4. On the Location tab, specify the path to the target folder and click Finish.

    Specify the path to the target folder

  5. Click Publish to publish your application to the selected folder.

    Publish the application

    If you need to modify your publish profile, click Show all settings and change project configuration in the Profile settings dialog.

    Change publish profile settings

Deployment Options

Single Executable

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)

Specify the 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)

Run the 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).