DEV Community

Cover image for Create .NET Core 3.0 trimmed self-contained single executable app using VS Code
Abubakar Siddiq
Abubakar Siddiq

Posted on • Originally published at dotnetdetail.net

Create .NET Core 3.0 trimmed self-contained single executable app using VS Code

In this tutorial, we are going to learn how to create a Asp.NET Core 3.0 trimmed self-contained app using visual studio code. In this way we can share our application without installing .NET SDK on the target machine. So, first-of-all, we will create an Asp.Net Core 3.0 app, then we will publish it as self-contained app and then we will see how to reduce the files using PublishSingleFile flag and then we will see how to reduce the size of executable using PublishTrimmed flag which is a new feature of .NET Core 3.0 Preview 6.

Prerequisite of this tutorial

Before going to the next, you must have installed these below prerequisites.

  • Visual Studio Code
  • .NET Core 3.0 Preview 6

How to create a .NET Core 3.0 trimmed self-contained single executable app using VS Code?

Let’s see how to create a .NET Core 3.0 trimmed self-contained single executable app using VS Code in step by step.

Step # 1: Create an Asp.Net Core 3.0 app using VS Code.

So, first-of-all, in this step we will create an Asp.Net Core app using Visual Studio code. So, open Visual Studio code, then open command terminal and then choose directory where you want to create your project and then run this below
command.

dotnet new mvc

After running the above command, you will see a new “Asp.Net Core web App (Model-View-Controller)” project is created.

Now, run this project by running this below command.

dotnet run

Now, you will see the output as you do see in the below screenshot.

Step # 2: How to publish self-contained app?

Now, in this step, we will see how to publish the self-contained app. So, go to terminal and run this below command.

dotnet publish -r win10-x64 -c Release --self-contained

So, the above command will build the app in release mode and will publish the self contained app. It will create a new folder with the name of publish which will have lots of files with the .exe file. So, now we can run this app on any other machine. We just need to copy the complete folder and paste in any other machine. Then finally, run the .exe file.

So, we have publish folder with lots of files and the size is also huge as you see below screenshot. So, the question is, how can we reduce the files and the size? Let’s see in the next step.

Step # 3: How to Reduce the files in self-contained app?

In this step, we will see how to reduce the files in self-contained app. So, according to .NET Core 3.0 Preview 5, we can publish a single-file executable using PublishSingleFile flag. Let’s see how it works.

Now, run this below command.

dotnet publish -r win10-x64 -c Release /p:PublishSingleFile=true

Now, you will see the output as you do see in the below screenshot.

So, as you see the above we have reduced our files. There is only one .exe file with web.config file. But, the problem of size is still the same as you see in the below screenshot.

Let’s see how to reduce the size.

Step # 4 : How to reduce the size of self-contained app?

In this step, we will see how to reduce the size of self-contained app. So, according to .NET Core 3.0 Preview 6, we can reduce the size of self-contained app using PublishTrimmed flag. Let’s see how it works.

Now, run this below command and publish self-contained app.

dotnet publish -r win10-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true

Now, you will see, the above command will give you the output as you do see in the below screenshot.

Thank you for reading. Please keep visiting and sharing it within your community.
You can read more about application deployment here in below links:
How to deploy Angular 6 and Asp Net Core Application in IIS 8?
How to deploy Angular 6 & Asp Net Core App to Azure using Visual Studio
Continuous Integration and Continuous Deployment in DevOps using Visual Studio 2019

Top comments (0)