You could do the reversed and set the Application output type to: Windows Application. Then add this code to the beginning of the application.
[DllImport("kernel32.dll", EntryPoint = "GetStdHandle", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern IntPtr GetStdHandle(int nStdHandle); [DllImport("kernel32.dll", EntryPoint = "AllocConsole", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern int AllocConsole(); private const int STD_OUTPUT_HANDLE = -11; private const int MY_CODE_PAGE = 437; private static bool showConsole = true; //Or false if you don't want to see the console static void Main(string[] args) { if (showConsole) { AllocConsole(); IntPtr stdHandle = GetStdHandle(STD_OUTPUT_HANDLE); Microsoft.Win32.SafeHandles.SafeFileHandle safeFileHandle = new Microsoft.Win32.SafeHandles.SafeFileHandle(stdHandle, true); FileStream fileStream = new FileStream(safeFileHandle, FileAccess.Write); System.Text.Encoding encoding = System.Text.Encoding.GetEncoding(MY_CODE_PAGE); StreamWriter standardOutput = new StreamWriter(fileStream, encoding); standardOutput.AutoFlush = true; Console.SetOut(standardOutput); } //Your application code }
This code will show the Console if showConsole is true