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.
Give the proper name to your project and click on Create.
We are creating this app for just learning deployment modes so select API as a template and click on Create button.
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.
Now it will ask for target then select Folder.
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.
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.
Finally, click on the Publish button to publish your app in FDD mode.
Open the folder where the final published app contains 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).
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.
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).
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 about what could I have done better.
Happy Coding!