Compiling XNA programs on the command line

Download and unzip the minigame source files

Install the XNA 4.0 redistributable

  1. Download Microsoft XNA Framework Redistributable 4.0 Refresh from Official Microsoft Download Center
  2. Install

Note: XNA 4.0 requires at least .NET 4.0 and DirectX 9.

Alternative minimal installation

  1. Unpack the XNA assembly DLLs from the installer to the colorsquare\ sources directory, for example using lessmsi. The complete list of required assemblies is:
  2. Install the Visual C++ 2010 Redistributable, or unpack the VC++ DLLs from the XNA installer into the sources directory:

Total size: < 3 MB

cd into the sources directory on the command line

cd colorsquare

Compile the C# sources

All on one line

C:\Windows\Microsoft.Net\Framework\v4.0.30319\csc.exe /r:C:\Windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.dll,C:\Windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Game\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Game.dll,C:\Windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Graphics\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Graphics.dll /target:winexe /out:colorsquare.exe *.cs

Broken across multiple lines using ^ carats

C:\Windows\Microsoft.Net\Framework\v4.0.30319\csc.exe ^
/r:C:\Windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.dll,^
C:\Windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Game\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Game.dll,^
C:\Windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Graphics\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Graphics.dll ^
/target:winexe /out:colorsquare.exe *.cs

If XNA Game Studio is installed

C:\Windows\Microsoft.Net\Framework\v4.0.30319\csc.exe ^
/lib:"C:\Program Files\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86" ^
/r:Microsoft.Xna.Framework.dll,Microsoft.Xna.Framework.Game.dll,Microsoft.Xna.Framework.Graphics.dll ^
/target:winexe /out:colorsquare.exe *.cs

Putting csc.exe on the %PATH% first, and assuming the DLLs have been copied to the sources directory

set PATH=%PATH%;C:\Windows\Microsoft.NET\Framework\v4.0.30319\
csc /r:Microsoft.Xna.Framework.dll,Microsoft.Xna.Framework.Game.dll,Microsoft.Xna.Framework.Graphics.dll /target:winexe /out:colorsquare.exe *.cs

Run

colorsquare

Found a mistake?

Submit a comment or correction

Links

Command-line Building With csc.exe
Working with the C# 2.0 Command Line Compiler

Updates

10 Feb 2019 Update some of the links
24 Apr 2013 Corrected compile commands for redistributable-only vs. game studio
23 Apr 2013 Posted