Make EXE console application C
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
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
- 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.
Normally,
the exe can be found in the debug folder, as suggested
previously,
but not in the release folder, that is disabled by default
in my configuration.
If you want to activate the release folder, you can
do this:
BUILD->Batch Build And activate the "build" checkbox in the release
configuration. When you click the build button,
the exe with some
dependencies will be generated.
Now you can copy and use it.
Comments
Post a Comment