This tutorial shows you how you can compile a simple piece of code from the C# command prompt compiler and how to add references.
This tutorial will show you how to compile C# code from the DOS command prompt. It doesn’t analyze all the parameters you can pass to the compiler and any other compiling methods, it only shows you how to compile a simple piece of code.
First we have to create a C# file that we shall compile:
Paste this into Notepad and save it at C:\toCompile\Form1.cs.
Now from the Start Menu in the Microsoft Visual Studio .NET\Visual Studio .NET Tools program group, open Visual Studio .NET 2003 Command Prompt:
The command prompt compiler starts:
We change to the toCompile directory using the command CD C:\toCompile at the command prompt:
Now let’s try to compile the program using the csc command. But first, we should not forget that we need to add some references like we usually do in Visual Studio.
Type csc /? in the command prompt to list the help associated with this command. You can see that using /reference we can add references for the compilation of the code:
Now that we know how to add a reference we can compile.
That’s it. You can now open the compiled application by typing Form1 because the file Form1.exe is in the toCompile folder.
When you run the application you’ll see that a console window and an empty form will pop-up.