2

Program requires several modes that depend on arguments:

  • Testing mode - console window is required for tracing
  • Normal mode requires windows forms GUI

I can build application with Application Type: Console Application (that provides console window for application) and Windows Forms Application (that lacks console window). No application type satisfies my requirements. If I build application as console application then useless console window exists with windows forms GUI. If I build application as windows forms application - there is no console window and I can't observe console tracing.

I guess I should redirect console output and build application as windows forms application but may I simply switch Application type programmatically (show or hide console window itself?)

Thank you in advance!

user149691
  • 587
  • 1
  • 5
  • 19
  • 1
    possible duplicate of [How do I show a console output/window in a forms application?](http://stackoverflow.com/questions/4362111/how-do-i-show-a-console-output-window-in-a-forms-application) – Honza Brestan Jul 03 '14 at 19:20
  • 1
    If your traces are going to standard output, you can redirect those into a log or a string you display in a debug window, eliminating the need for a console. – Seth Moore Jul 03 '14 at 19:21
  • Why not simply add an output window to your graphical application? Then you get better copy and paste, and other operations you might want to do on the text (like searching or whatever). If you want to hide this in production, simply don't add whatever UI control brings up that window if you aren't running a debug configuration. If it's file output you want, just create a switch in your application that when it's compiled under debug, it emits a trace log file in a well-known location. – Clever Neologism Jul 03 '14 at 19:22
  • Why do you need a Console application for testing. Why don't you just use testing framework for testing for instance, NUnit? – AR5HAM Jul 03 '14 at 22:43
  • @Arsham, testing is mode when program tests it's current environment. Tests database connection, tests that hardware key is present, tests other external system dependencies. It's for administrators purposes only – user149691 Jul 04 '14 at 07:52

1 Answers1

0

As I and others mentioned in the comments, you should really send your traces to a log or a string you display in a debug window, eliminating the need for a console.

But, if you really want to do this, you can change <OutputType>WinExe</OutputType> in the csproj file to <OutputType>Exe</OutputType>. This will run your WinForms project and also pop up a console window.

It looks like you could configure your csproj to have a different OutputType depending on which mode it's being run in: Changing csproj OutputType based on project configuration

Community
  • 1
  • 1
Seth Moore
  • 3,575
  • 2
  • 23
  • 33
  • Mode is set by parameter when I execute a program. Program was compiled at this moment - it's too late to change anything in csproj. – user149691 Jul 04 '14 at 07:50
  • Then you answered your own question. You can't compile your project as a different type at runtime. It looks like the way to is to write traces out to something other than the command line. – Seth Moore Jul 07 '14 at 14:27