Deployments Modes in ASP.NET Core 3.1
Tags: dotnet, webdev, dotnetcore, csharp
Published: 2020-02-04 18:35:35

> This article is originally published [here](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/).

In this article, we will be discussing the different deployment modes in .NET Core 3.1. Once we develop any application we have to deploy it somewhere and to do this we have to create a build of our app. So .NET Core provides 3 different types of deployment modes for accomplishing this task.

* Framework-dependent deployment (FDD)
* Self-contained deployment (SCD)
* Framework-dependent executables (FDE)

So in this article, we are going to discuss the above deployment modes one by one and also see how to publish the app using the above modes.

## Framework-dependent deployment (FDD)

As the name specifies, in case of framework-dependent deployment mode application is completely dependent upon the .NET Core installed on the target machine where you want to deploy your app. Framework-dependent deployment (FDD) is the default deployment mode in .NET Core app. The application only contains the app-specific code and external dependencies. As the .NET Core needs to be already installed on the server your build size also becomes small. You can share the same .NET Core runtime along with multiple application. The .dll will be running with the help of a utility called **dotnet**.

#### Benefits of Framework-dependent deployment (FDD) 
* The app will only contain code and its external dependencies. So it will also reduce the final build size.
* This mode uses the same .NET Core install on server, so it will also reduce the disk space and memory cost.

## Self-contained deployment (SCD)

As the name specifies, Self-contained deployment (SCD) does not use the common .NET Core install on the server. The final application build contains all the app-specific code and its dependencies along with .NET Core libraries and .NET Core runtime. In this mode, it is not necessary to have .NET Core runtime install on the servers.

As .NET Core is cross-platform, we can build our code depending upon the platform we want to run the app. There are 6 different target platforms available:

* win-x86
* win-x64
* osx-x64
* linux-x64
* win-arm
* linux-arm

But in SCD the final build size is larger than FDD because the SCD not only contains the app and its dependencies but also contains .NET Core libraries and .NET Core runtime.

#### Benefits of Self-contained deployment (SCD)

* As the app is not using shared the .NET Core runtime, we can deploy multiple apps with different versions of .NET Core.
* In SCD we will be more confident that our app will be running on a target system since you're providing the of .NET Core Runtime that it will run on in the final build.


## Framework-dependent executables (FDE)

This mode is included form .NET Core 2.2. It is exactly same as FDD but this mode produces the executable that can be run on any target machine. In this mode, we are not using dotnet utility to run our app.

## Published your ASP.NET Core Web API as FDD

First, we are going to create new ASP.NET Core Web API. So open Visual Studio and Go to File -> New -> Project. Select ASP.NET Core Web Application and click on Next.

![select-new-project](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/Images/new/select-aspnet-project.PNG)

Give the proper name to your project and click on Create.

![create-project](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/Images/new/create-project.PNG)


We are creating this app for just learning deployment modes so select API as a template and click on Create button.

![new-app](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/Images/new/new-app.PNG)

Now in this section, we will be focusing on how to publish ASP.NET Core Web API. So right-click on a new project and click on the Publish button.

![published-button](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/Images/new/published-button.png)

Now it will ask for target then select Folder. 

![pick-up-target](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/Images/new/pick-up-target.PNG)


Now click on 'Advanced..'. Now in this section, we have to decide in which mode need to use while creating a build for our app. So now select Framework-dependent as Deployment mode and Target Runtime as Portable & click on Save button. 

![published-option](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/Images/new/published-option.PNG)

Now click on the Create Profile button. So this will create a new profile for us which we can use for next time to publish our app.

![pick-up-target-copy](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/Images/new/pick-up-target%20-%20Copy.PNG)

Finally, click on the Publish button to publish your app in FDD mode. 

![final-published-button](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/Images/new/final-published-button.PNG)


Open the folder which contains the final published app and you will see it only contains app-specific .dlls bcoz we selected deployment mode as FDD and its size is also small (292 KB).

![FDD-output](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/Images/new/FDD-output.PNG)

You can deploy the application using Dotnet CLI as well. So open your developer tool at your project path and run the below command to publish your app in FDD mode. 

```
dotnet publish -c Release

```
So this way we can publish our app with FDD mode.


## Published your ASP.NET Core Web API as SCD

Now in the previous section, we have published our app using FDD mode. Now we are going to publish the same app using SCD and you will see the difference with the output and size of the published folder.
 
Again click on the solution and select Publish option. As we have already created a profile so you can edit existing profile or you can create a new one as well. We will edit an existing profile.  

![select-edit-option](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/Images/select-edit-option.PNG)

![scd](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/Images/self-contained-mode.PNG)

Now select Target Runtime as per your preference. After that Save the profile and click the publish button. Final build folder contains our app .dlls along with .net core runtime, but the build size is large (85.3 MB).

![scd-folder-app](https://www.c-sharpcorner.com/article/deployments-modes-in-net-core-3-1/Images/scd-folder-app.PNG)

You can deploy the application using Dotnet CLI. So open your developer tool at your project path and use below command to publish your in SCD mode.

```
dotnet publish -c Release -r <RID> --self-contained true

```
So here -r specifies target runtime and <RID> is the Runtime Identifier like win-x86,win-x64, etc.

## Conclusion

In this article, I have explained about the different modes of deployment provided by .NET Core. Also, demonstrate how to publish the ASP.NET Core Web API using FDD & SCD deployment modes.
 
I really hope that you enjoyed this article, and please do not hesitate to send me your thoughts or comments.
 
Happy Coding!