.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Create Windows Application in C# from Command Line

Posted By:Kirtan       Posted Date: April 24, 2010    Points: 25    Category: C#    URL: http://www.dotnetspark.com  

The article explains how to create /compile a Windows Forms application program from command line using C# compiler without using Visual Studio IDE.


Here is trick to build and compile a C# Windows Forms application without using Visual Studio IDE.

This approach is not recommended but this is something you should know when you have only command line interface and want to create some handy utilities. If you do not have a Visual Studio IDE, you may download Express versions for free from MSDN website.

In this article, we are going to create a sample Windows Forms application that will create a Form with a Button control and click on the button will display a text using a MessageBox. 


.Net 2.0/3.5




1. .NET Framework 2.0/3.5
2. Visual Studio 2008/2005
3. Programatically Event Handling Knowledge   

Step 1.

Fire up Notepad and write C# Program like below. As you can see from this code, we first import System and System.Windows.Forms namespaces.

//Declare Name Spaces
using System;
using System.Windows.Forms;

// Display Controls on Form Programatically

namespace TestGUI
class Test:Form
// Create Constuctor of Class

// Global Variables
public TextBox t1;
public Button b1;


//Suspend the layoutl logic

//Set Properties of Button a
b1=  new Button();
b1.Location =new System.Drawing.Point(30,40);
b1.Text = "Click Me";

//Add handler to Button
b1.Click += new System.EventHandler(b1_Click);

//Set Properties of Text Box
t1 = new TextBox();
t1.Location  = new System.Drawing.Point(20,20);

//Add Conponents on form

//Give Form title
this.Text = "GUI Without VS";

//Resume the layout



public void b1_Click(Object Sender,EventArgs e)
MessageBox.Show("Hello you Clicked Me");
//Now every thing is done Lets Build The Main method
public static void Main()
Application.Run(new Test());



Step 2. Compilation

Save the text file and name it GUITest.cs.

Now open Cmd and change directory to C:\Program Files\Microsoft Visual Studio 8\VC\


cd  C:\Program Files\Microsoft Visual Studio 8\VC\


then enter the command  to compile the exe here target is type of output we want and /out  is used to create our output file.

Command looks like this here you want to make sure the path of Exe and .cs files matches on your machine.

csc.exe /target:exe /out:c:\Users\Kirtan\Desktop\GUITest.exe C:\Users\Kirtan\Desktop\GUiTest.cs

3. Run

Now if you go to your desktop, you will see GUITest.exe is there. Just double click on that and run it.


The article explained how to create Windows applications using C# compiler from command line without using Visual Studio IDE.

Thank you
 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend