Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
3.60/5 (5 votes)
See more:
If it is difficult, then is there a portable compiler that I can use?
Posted

You compile it from the command line using csc.exe.

 
Share this answer
 
The C# Express Edition is free. So is SharpDevelop.

 
Share this answer
 
It's not difficult and more developers should learn to do it; it's a very useful tool to have.

When you install .net, the C# and VB.net compilers are installed as well (these are the same compilers that Visual Studio uses).

0. Open a DOS box; there are at least two ways to do this:
Start|Run cmd
Start|Programs|Accesories|Command prompt

Because I use a DOS box extensively I have it on my Quick launch toolbar

1. Determine which versions of the compiler you have:

<br />C:\>dir /s /b "c:\windows\microsoft.net\framework\csc.exe<br />c:\windows\microsoft.net\framework\v1.1.4322\csc.exe<br />c:\windows\microsoft.net\framework\v2.0.50727\csc.exe<br />c:\windows\microsoft.net\framework\v3.5\csc.exe<br /> <br />C:\><br />


2. Execute the compiler of your choice, specifying your source code as a parameter:

<br />C:\>c:\windows\microsoft.net\framework\v3.5\csc.exe Hello.cs<br />Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.1<br />for Microsoft (R) .NET Framework version 3.5<br />Copyright (C) Microsoft Corporation. All rights reserved.<br /><br />C:\><br />


3. Execute the program:

<br />C:\>hello<br />Hello, world!<br /><br />C:\><br />


4. If you do this frequently, you may want to write a BAT file to do this:

<br />C:\>type csc.bat<br />@c:\windows\microsoft.net\framework\v3.5\csc.exe %*<br /><br />C:\><br />


5. And/or add the compiler's directory to the Path environment variable
Start|Settings|Control panel|System|Advanced|Environment variables|System variables|Path|Edit
 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900