48

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?

4
  • Won't Visual Studio Express work for you?
    – svick
    Jun 7, 2013 at 17:28
  • 2
    @svick: If I would need to have it to compile the project, then I would use it. But in this case it isn't necessary, so I don't have to install it on every machine where I want to deploy the project. I can simply pull a copy from the VCS, compile it and run it. Installing VS Express would have overcomplicated the whole process. Jun 7, 2013 at 17:34
  • In that case, a simpler solution might be deploy a compiled assembly. That way, you don't have to do any compiling on every machine.
    – svick
    Jun 7, 2013 at 17:38
  • 1
    @svick: Thanks for your insight, but deploying binaries briefly crossed my mind as well. If I had considered it a beneficial alternative in this case, I would have done it. That being said, this question and answer were posted to simply describe a process. Deciding if this process is the way to go in the users case is a decision left to them. Jun 7, 2013 at 17:45

2 Answers 2

45
  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/
    
14
  • Nice! Any MSBuild documentation links? Also, this is for a VS project one already has, right? What about compiling code in .CS or other source files?
    – Karan
    Jun 7, 2013 at 14:35
  • 2
    @Karan - Anyone care to make an answer based on this article msdn.microsoft.com/en-us/library/vstudio/78f4aasd.aspx?
    – Ramhound
    Jun 7, 2013 at 14:37
  • @Ramhound: I guess someone knowledgeable can as well incorporate all this into a single FAQ-type answer. Also some follow-up questions that can be addressed. Is csc.exe also bundled with an end-user .NET framework install? Is it included if you only install the Client Profile?
    – Karan
    Jun 7, 2013 at 14:42
  • 1
    @Karan: I've added a link to the MSBuild.exe command line argument documentation. Yes, this is for a project that is already on the local machine (maybe downloaded from GitHub). As Ramhound mentions, csc.exe would be the go-to tool to compile single files. csc.exe is bundled with the .NET Framework as well. It is the core C# compiler and MSBuild probably just invokes it. Not sure about the client profile, but I would assume they are included with it. Jun 7, 2013 at 14:49
  • 1
    One reason that csc.exe needs to be included is because the Client Profile includes the XmlSerializer class. This class generates serialization assemblies (using csc.exe) at run-time.
    – heavyd
    Jun 8, 2013 at 19:07
5

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.

2
  • 2
    Is there any reason one would use mono on windows?
    – Rishav
    Mar 30, 2018 at 15:13
  • 2
    @Rishav Political considerations? Perhaps for one who is required to use Windows but wants to use as little other Microsoft technology as possible. Just speculating, though.
    – Jamie
    Aug 17, 2018 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.