I'm trying to automate some tasks for myself and I wrote a few .NET Core 1.0 console applications. One of them is BrowserRouter - a simple application which, based on a URL pattern, decides which browser / browser profile to open when I click on HTTP(S) links.
That works fine, but there is always the console window which appears and immediately disappears.
Is there a way to run the .NET Core console application silently (hiding the console window)?
I know in the full .NET Framework it is possible to change the output type to Windows Application, but that's not available (yet?) for .NET Core.
If you do not know what I am talking about: press Win+R, type “help” and press ENTER. A black console window will open, execute the HELP command and close again. Often, this is not desired. Instead, the command should execute without any visible window.
You can do it right in Visual Studio. Right click the Console App Project and select Publish. Then change Deployment Mode to Self-contained or Framework dependent. . NET Core 3.0 introduces a Single file deployment which is a single executable.
Build and run your code in Visual Studio To run the code, on the menu bar, choose Debug, Start without debugging. A console window opens and then runs your app. When you start a console app in Visual Studio, it runs your code, then prints "Press any key to continue . . ." to give you a chance to see the output.
Try Ctrl + F5 in Visual Studio to run your program, this will add a pause with "Press any key to continue..." automatically without any Console. Readline() or ReadKey() functions.
Update 2018: In .NET Core 3.0+, you will be able to set <OutputType>WinExe</OutputType>
inside of the csproj file.
Currently, this is not directly possible out of the box because Windows EXE files contain a flag indicating if it is a "console" or "GUI" application that Windows evaluates even before starting the application. However, this flag can be changed using editbin.exe
(ships with Visual Studio' C++ build tools as far as I know).
Building on this, you could create a self-contained .NET Core application (removing the "type": "platform"
from the project.json
and adding a runtimes section) so your project output includes an actual .exe
file and add a post-build script that invokes editbin.exe /subsystem:windows yourapp.exe
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With