[ WPF Application with GUI and Console modes ]
I understand that there are problems regarding running a WPF application from a console window and outputting to the console rather than showing a gui (aka This Question).
The 'conclusion' of that question (which appears to be well researched and asked) is that it is possible to output from the application to the console, but it returns immediately - rather than blocking like a console application would.
However, looking at Visual Studio particularly the 'devenv.exe' process, this is exactly what it does manage to do:
- Double clicking on devenv.exe from within explorer runs the application gui only.
- From within a console (cmd.exe) window
devenv.exe<enter>
runs the Gui returning to the console immediatelydevenv.exe /?<enter>
displays the help within the console, only returning after all output has been displayed.devenv.exe test.txt<enter>
runs the Gui (loading test.txt) returning to the console immediately
So, it must be possible to have this behaviour in our own applications somehow! Does anyone know how?
Answer 1
On an informational note, this article here explains how Visual Studio does it. I quote:
In VisualStudio case, there are actually two binaries: devenv.com and devenv.exe. Devenv.com is a Console app. Devenv.exe is a GUI app. When you type devenv, because of the Win32 probing rule, devenv.com is executed. If there is no input, devenv.com launches devenv.exe, and exits itself. If there are inputs, devenv.com handles them as normal Console app.
Answer 2
Go into your App.xaml and remove the Startup Uri and all references to your main Application Window which is started.
You can override the OnStartup Uri. See this Question: WPF Command Line