half-baked prgrmr
half-baked prgrmr

Reputation: 45

C# Console and GUI Application in one

This is in continuation to my earlier question here myPost. That was a kind of a flop question. Somehow we will modify that in Java and use it.

To move further, I have decided to re-do that project in C# which I am more comfortable with. To begin with I hit a roadblock. In that java application, the actual coding is done in Eclipse and the .jar can be executed through command line. Also a GUI is done using Netbeans which refers to the actual program in Eclipse. So the same appl is used as a command line as well as GUI.

How can I do this in C# ?? Just write the code once and then execute .exe or through GUI, but both will work independently.

Upvotes: 0

Views: 1759

Answers (3)

G3n1us
G3n1us

Reputation: 26

Create a C# class library that contains public methods that do the work. You can then reference the C# class library from any interface you'd like to offer the user.

Upvotes: 0

gretro
gretro

Reputation: 2009

The best way to create an "hybrid" application would be to decouple your logic from your UI representation (MVC, MVP or MVVM). This will create two .exe (one in GUI, one in command line) and a dll which will include the Business Logic.

This way, you're also making sure that your application can be more easily modified and maintained in the future.

Upvotes: 0

dgvid
dgvid

Reputation: 26633

In the .NET world, this is often done by putting the "guts" of the application in a library assembly which is then used by both the GUI and console application projects. So for example, you might set up a solution with three projects:

  1. A Windows Form application
  2. A console application
  3. An assembly library with that does the actual work

Upvotes: 3

Related Questions