Walker News

How To Use C# Command-line Compiler To Compile CS File?

A video guide shows how to use the free C# compiler (csc.exe) to compile source code (.cs file) on Windows 7 Command Prompt for an executable .Net program.

Though the video is using latest C# compiler version 4.0.30319.1, it is good to serve as general reference for older or newer version of .Net compilers, including C/C++.Net (cl.exe) and VB.Net (vbc.exe):

  1. Download and install Microsoft Windows SDK for Windows 7 and .Net Framework 4. Prior to .Net Framework 3.0, the .Net command-line compilers were bundled with .Net Framework SDK.
  2. Add the path of Windows SDK bin folder that contains SetEnv.cmd to Windows system path so that you can configure the build environment on Command Prompt opened at any working directory.
  3. To make life easier when working with Windows Command Prompt, consider the trick of adding Command Prompt shortcut to Windows context menu.
  4. Open Command Prompt window and change working directory to folder containing the cs file (C# source code file) and execute setenv to setup SDK environment.
  5. Now, it is ready to run any .Net compilers (csc, cl, vbc) to build .Net program from source codes on Windows Command Prompt!

To build a C# console program, such as wfslog – freeware used to monitor Windows file changes, the syntax can be as simple as this:
csc wfslog.cs 

Custom Search

2017  •  Privacy Policy