When I create a Console Application in Visual Studio, a cmd Window is automatically provided on which text can be written to and read from. Where is this behaviour set up? Does VS do it or is it merely a consequence of a compiled .Net program?
On a side note, how does VS hook System.Diagnostics.Debug.WriteLine("This is magic"); up to the output Window?
The console behaviour is part of the PE header in the exe; there is a flag to distinguish between console and windows apps. The value of this flag is pretty much the only fundamental difference between a windows exe and a console exe (you can still create forms from a console exe, etc – and you can write to the console from a windows exe, although you won’t be able to see anything).
You can toggle this flag using
editbinif you want to play with it – the/subsystem:windowsflag, in particular.The debug output is because the debugger attaches to pre-defined trace points to gather the output. If you press ctrl+f5 it runs without attaching any of these hooks, so you get something closer to running it directly from the shell.