Create four separate configurations, two for the GUI and two for the console:

The above screenshot is for solution configurations. Youll have to do the same again for the project (in the screenshot above, a project that has these four configurations is Rummage). Here is an excerpt from Rummage.csproj
:
[...] <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugGui|AnyCPU' "> <OutputType>WinExe</OutputType> <DefineConstants>DEBUG;TRACE</DefineConstants> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseGui|AnyCPU' "> <OutputType>WinExe</OutputType> <Optimize>true</Optimize> <DefineConstants>TRACE</DefineConstants> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugConsole|AnyCPU'"> <OutputType>Exe</OutputType> <DefineConstants>DEBUG;TRACE;CONSOLE</DefineConstants> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseConsole|AnyCPU'"> <OutputType>Exe</OutputType> <DefineConstants>TRACE;CONSOLE</DefineConstants> <Optimize>true</Optimize> </PropertyGroup> [...]
Please note especially:
Console configurations have <OutputType>Exe</OutputType>
(which makes them a console application), while Release configurations have <OutputType>WinExe</OutputType>
.
Both console configurations have a CONSOLE
constant. That way you can use #if CONSOLE [...] #else [...] #endif
to get console / GUI specific code. For example, the Main method might look like this:
[STAThread] static int Main(string[] args) { #if CONSOLE return MainConsole(args); #else return MainGui(args); #endif }
... and then you can use WinForms stuff in MainGui
and parsing the line at the MainConsole
command prompt.
Thus, you can run (and debug) either the graphical interface or the console version in Visual Studio, and in the script assembly you can simply collect all of them (and in different directories or different EXE file names).
Timwi source share