Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why all .NET Core applications are console applications?

Tags:

.net-core

I have a very basic question about why all .NET Core applications are console applications. I did some google search but don't find any appropriate answer.

like image 320
Asif Rehman Avatar asked Oct 28 '25 08:10

Asif Rehman


1 Answers

It's an interesting question, and I got here because I had the same thought: Why do I seem to always see a console on asp.net core apps? Are they all now console apps?

But it's a mirage. While you are seeing a console window, it's only because the code is using the console for output. The code that starts the app governs where the output is going to. For example, instead, the output could be ported to the Windows Event Log, which is what happens when the site is published to IIS.

If you create a default .netcore web app, and you look in the output directory, you will see two files:

YourProject.exe YourProject.dll

If you double click the exe, it will start the website. You will see the console window appear and the app will start listening on port 5000.

But now rename YourProject.dll and try to run the exe. It will fail because the exe is just the startup code. Your website is actually in the .dll.

The point is that the console window you see when you start an web app is coming from the exe, not the dll. So the console window has nothing to do with your web app, it's just a convenient way to start up the app in a dev environment. You can also start it from the command line with dotnet YourProject.dll and it will run exactly the same as if you started it from YourProject.exe

If you read @HansPassant's comment, he says it exactly correctly, my answer is just an expansion of it.

like image 53
Greg Gum Avatar answered Oct 30 '25 10:10

Greg Gum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!