How can I compile a .NET project without having Visual Studio installed?

I want to compile a .NET/C# project, but I don't want to install Visual Studio to do this.

What tools do I need and how can I compile the project?


Solution 1:

  1. Download and install the latest .NET Framework.
    For example, you can use the installer for the .NET Framework 4.5 installer.

  2. Open a command prompt and change into the installation directory of the .NET Framework.
    For example:

    cd \Windows\Microsoft.NET\Framework\v4*
    
  3. Use MSBuild.exe to compile your solution.
    For example:

    msbuild "C:\Users\Oliver\Documents\My Project\My Project.sln" /t:Rebuild /p:Configuration=Release /p:Platform="Any CPU"

In case the project uses NuGet packages, you can follow these steps to retrieve them:

  1. Download the NuGet.exe Command Line boostrapper and, for example, place it inside the solution directory.

  2. Open a command prompt and change into the solution directory.
    For example:

    cd "C:\Users\Oliver\Documents\My Project"
    
  3. Invoke NuGet.exe to update the packages required for this solution:

    NuGet.exe install "My Project/packages.config" -o packages/
    

Solution 2:

If you want to avoid installing Visual Studio, you might want to try Mono, a cross-platform and open source .NET runtime and development framework. Mono is based on the published ECMA standard for C# and is directly compatible with pre-compiled C# applications.

Mono also includes a tool called XBuild which can fully replace MSBuild. See this article from the Mono project regarding porting a project from MSBuild to XBuild. A one-line description of XBuild from the Wiki:

xbuild is Mono's implementation of msbuild and it allows projects that have an msbuild file to be compiled natively on Linux.

Note that in addition to Linux, Windows and Mac OS X are also supported.