How To Create EXE For .Net Core Console Application

In this article, you will learn how to create an exe for .NET Core Console application.

A few days back, I got a requirement to create a .NET Core Console application and give it to my test team as an exe application for their testing. Well, I created a .NET Core console application and wrote all the business requirements.
 
But when I opened the app and the debug/release folder, I did not find the exe available there, as we were in the .NET Framework application.
 
Then, I found out a solution for it which will help us create an exe from a .NET Core Console application.
 
Let’s see it with example.
 
Step 1
 
Create a .NET Core Console application and click on the OK button. Here, I have created an application and when I build this solution, my expectation is to get the exe file available in the debug/release folder.
 
 
Step 2
 
Build the solution and open the corresponding folder just like in the below image.
 
You can see that we do not have any exe files there in this folder. But I would like to inform you that this is not a bug. In .NET Core, it runs from the dll, so you have to just run the application by running the command prompt and using the command - dotnet run.
 
Step 3
 
Open your command prompt and go to that folder where your application persists.
 
 
Then, just type only dotnet run (Your application Name .dll)
 
For example, in my case,
 
dotnet run ConsoleApp1.dll
 
This resulted in printing "Hello World!" as it is written in our console application. The benefit of executing the application in this mode is that this DLL file (which is not required by exe) works across all platforms that are supported by the .NET Core Runtime (Windows, Linux, and macOS).

This is called a "portable" or "framework dependant" deployment. But, the exe will work only on the targeted machine. 
 
Step 4
 
Now, the step comes where if we want to generate the exe for our .NET Core Console application, we need to write some command. Or from VS UI, we can generate the exe.
 
So, let’s see this with commands here.
 
I have already moved to my console application location; then I write this command on the command prompt.
 
dotnet publish -c Debug -r win10-x64
 
See the attached image. We can now see that the exe has been generated in the folder.
 
 
See in the above command I have created exe in debug folder, but if we want to create it in release mode, which we can say is for production, then we have to change the  command and in place of debugging, we have to write Release like this,
 
dotnet publish -c Release -r win10-x64
 
Now, we have done our part of the objective.
 
Here, if we want to generate exe from VS UI as above I have told you, then let’s see how we can achieve the same thing.
 
Step 5
 
Right-click on your project solution and click on the Publish button. Select the folder option and then click on the Publish button.
 
 
Then, you will get another window like this.
 
Here, in this window, click on the Configure Link button. You will get another popup window just like this.
 
In this window, make sure you have selected the Deployment mode as self-contained from the dropdown and the Target runtime is win-86
 
Then, click on the Save button, and finally, publish it. You will get the same result.
 
Thanks for reading, hope this helps. You can download the code from here.