How to compile a GUI application using mono?

I wrote a program in C # and I will compile as follows:

C: \ Users \ Administrator \ Documents \ Visual Studio 2005 \ Projects \ GUITest \ GUITest> mcs * .cs / r: System.Data, System.Drawing, System.Windows.Forms, .. \ HtmlAgilityPack.dll

But the output application has a console window. Is there a way to compile the program so that I can get the application without a console window?

+4
source share
1 answer

There are two different modes or types of Windows applications: console applications and graphics applications. The same goes for managed applications, no matter how you create them.

Console applications will always display the console window at startup automatically. You can also write code to display a GUI window (such as a form), but this is optional. In any case, the console window will always be displayed.

GUI applications do not display anything at startup. Typically, you write code that displays a GUI window (such as a form), but you do not need this. If you don’t see anything, you have created what people often call a “background application” because it runs in the background without displaying any user interface. This is not possible in a console application because it displays this ugly console window.

So, if you do not want a console window, you do not need a console application. You want to use a regular graphics application.

Now the problem is how to achieve this using the Mono compiler. Visual Studio provides this parameter as a project level parameter. The Mono compiler requires the /target flag to indicate which type of application to create.

  • /target:exe (default option) will build a console application
  • /target:winexe build a graphical application
  • /target:library build a library (which is not an executable application, but just a piece of reusable code)

So, change the command you execute on the command line to:

 mcs *.cs /target:winexe /r:System.Data,System.Drawing,System.Windows.Forms,... 

I believe that you will also need to make sure that you are using the relatively recent version of Mono. In older versions there was no support for creating GUI applications (the /target:winexe not implemented). I know that this is fully supported since version 2.8, but there is no reason not to use the latest available version.

If my answer is not credible enough for you, you will find the same quick fix (without justification) documented in the Mono WinForms FAQ .

+6
source

All Articles