This is a continuation of our previous articles:
Preview
In this article, we will learn how to create a deployment package for .NET Core console applications using the Self-Contained Deployment (SCD) approach.
As we know, we can create two types of deployment package for .NET Core application.
- Framework-Dependant deployment (FDD)
- Self-Contained deployment (SCD).
Let’s understand how to create a deployment of .NET Core application using the Self-Contained Deployment (SCD) approach. We will use the term SCD to represent “Self-Contained Deployment”. As compared to the FDD approach, files created using the SCD approach don't depend on the framework installed on our deployment version.
All the components, .NET Core libraries, and .NET Core runtimes will be included with application deployment files. So, you can expect that a bigger list of files will be created as compared to the FDD approach.
To make things simple, we will use the same application that we have created in our previous articles. So, if you remember, we have created the following two applications using .NET Core Framework.
- DotNetCoreDemo (.NET Core Class Library )
- DotNetCoreApp (.NET Core Console application)
We will publish the “DotNetCoreApp” application using SCD approach.
Step 1 Make changes at project.json file
Now to deploy an application with SCD approach, we need to modify some components of our "project.json" file from “DotNetCoreApp” application.
We need to make the following changes.
- Remove the "type" "platform" from “Microsoft.NETCore.App” section under the “dependencies”.
- Add the runtime section under the project.json. We will specify the platform that our application targets. For demo purposes, we target 32-bit windows 7 platform. So, we will add the following line under the project.json after the framework.
- "runtimes" {
- "win7-x86" {}
- }
Our final project.json will look like this.
Step 2 Publish the code
Right click on project with the name as “DotNetCoreApp” and click on Publish.
You will get the modal popup with a header as “Publish”. Select the “File System”. We have already created a folder with the name “Test” under the D Drive. Select the folder and click on “Next” button.
Make all the options as they are. Only Expand the “File Publish Option” and select the option “Delete all existing files prior to publish”. This action will clear the all previously created files. That will make your deployment folder neat and clean with a fresh set of files.
Step 3 Publish the application
Now, click on “Publish” button. Your application should publish the files successfully.
Let's have a look at the folder that contains our published code.
We can notice the following two very important points with SCD approach.
- We got the .EXE file for “DotNetCoreApp” project.
- More than 200 files were generated based on our approach selected.
There are two significant differences we can observe between the FDD and SCD approaches.
Now, let’s run our .EXE file and check the output.
What we have learned so far
- How to publish .NET Core console application using SCD (Self-contained Deployment) approach.
This was the last article on .NET core.
Let's summarize what we have learned from all four articles.
- How to create .NET Core class library and console application using VS 2015 community edition and .NET Core.
- How to add automation test case to .NET Core class library.
- How to create deployment package using FDD (Framework-Dependent Deployment) approach.
- How to create deployment package using SCD (Self-Contained Deployment) approach.
I hope all of these articles will help you to learn some of the very basic concepts of .NET Core.
In the next article, we will learn more about ASP.NET Core application and much more.