Introduction
Here is trick to Compile the C# Application Program without opening the Visual Studio it is not recommanded but this is somthing you should know when you have only command line interface and want to create some handy utility. In Article we are Creating Sample Program that Will Show Hello in MessageBox When We Click Button Technologies:
.Net 2.0/3.5
Language:
C# Prerequisite
1. .NET Framework 2.0/3.5 2. Visual Studio 2008/2005 3. Programatically Event Handling Knowledge
Implementation
Fire up Note pad
And Write C# Program like below
{codecitation class="brush: csharp; gutter: true;" width="650px"}
//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;
Test() {
//Suspend the layoutl logic this.SuspendLayout();
//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 this.Controls.Add(b1); this.Controls.Add(t1);
//Give Form title this.Text = "GUI Without VS";
//Resume the layout
this.ResumeLayout(false);
}
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()); }
}
}
{/codecitation}
Save the File With name GUITest.cs
and Then Open Cmd and change directory to C:\Program Files\Microsoft Visual Studio 8\VC\
by
cd C:\Program Files\Microsoft Visual Studio 8\VC\
command
then enter the Command to Compile the exe here target is Type of Out put we want and /out is used to Create our output file
csc.exe /target:exe /out:c:\Users\Kirtan\Desktop\GUITest.exe C:\Users\Kirtan\Desktop\GUiTest.cs
Conclusion
The Article Exlaines About how to compile program with csc.exe of Visual Studio . Thank you
|