Create .NET Core 3.0 trimmed self-contained single executable app using VS Code
Tags: dotnet, csharp, webdev
Published: 2019-07-31 08:09:00

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.
![](https://thepracticaldev.s3.amazonaws.com/i/opz0arxariffhelgz3u7.JPG)

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.
![](https://thepracticaldev.s3.amazonaws.com/i/cbh75i33x6p5a37kw9sd.JPG)
#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.
![](https://thepracticaldev.s3.amazonaws.com/i/0ksa96g3dmp08skqomff.JPG)
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.
![](https://thepracticaldev.s3.amazonaws.com/i/dkweqov70eh233zvihcg.JPG)
#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.
![](https://thepracticaldev.s3.amazonaws.com/i/kq67tu1kibmbdxyt9nxj.JPG)
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.
![](https://thepracticaldev.s3.amazonaws.com/i/yhl8iyiap59xb0uky0oi.JPG)
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.
![](https://thepracticaldev.s3.amazonaws.com/i/jcjvas070f3ihy4mjjwa.JPG)
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?](http://dotnetdetail.net/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](http://dotnetdetail.net/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](http://dotnetdetail.net/continuous-integration-and-continuous-deployment-in-devops-using-visual-studio-2019/)