77

I want to build projects from the command line. Is it possible to deploy a C# compiler without installing Visual Studio?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pavel Bastov
  • 6,911
  • 7
  • 39
  • 48
  • 5
    hehe, I find it funny how people associate the IDE with the actual development platform and/or language. – Soviut May 14 '09 at 03:34
  • That is the way I like to keep my build machine. Just the compiler. Of course some tools require Visual Studio, I find that really annoying in the context of build machines. You should not have to install Visual Studio in order to build anything. Some providers of 3rd party tools require Visual Studio to be installed in order to licence components and there was another reason we had to do it, can't remember what it was though. – Aran Mulholland Aug 09 '15 at 23:18
  • Indeed, it is needed by the framework for some parts of .NET. If you watch the processes on your production machine and are using some functionalities requiring runtime code generation like XML Serialization, you'll notice `csc.exe` being launched by your application from time to time. Even if VS is not installed. – Laurent LA RIZZA Jan 17 '16 at 14:46

11 Answers11

48

Sure, the framework includes a compiler, csc.exe. Look at this article for a quick how-to. The important parts:

You can get the command-line compiler (csc.exe) from Microsoft site http://msdn2.microsoft.com/en-us/netframework/aa731542.aspx.

Download the redistributable package of the .NET Framework, which includes the compiler and the .NET Framework with C# 2005 syntax support.

The compiler is located in the following directory: %windir%\Microsoft.NET\Framework\

Also look at this MSDN article for a full guide and explanation.

Note that for more recent versions, you will be looking for the MSBuild standalone package rather than the framework -- see @Vadzim's answer.

lc.
  • 113,939
  • 20
  • 158
  • 187
47

Of course. Do:

sudo apt-get install mono-gmcs

Everyone else assumed Windows and MS .NET, but...

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • Everyone assumed, because there is only one adequate OS for desktop - Windows. Above that people asks "not installing VS", meaning he is under Windows, but don't want to install VS (because VS doesn't exist for Linux). – Vincent Jan 28 '23 at 09:28
35

Yes, if you have the .NET SDK, it's there. For example,

C:\WINDOWS\Microsoft.NET\Framework\v[your version number]\csc.exe

msbuild.exe should be there too, and you can use that to build project (.csproj) files.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Brian
  • 117,631
  • 17
  • 236
  • 300
  • 19
    csc.exe is included in the .NET Framework, what most people think of as the runtime. You don't need the SDK to get the compiler. Let me say that again: you don't need the SDK to get the C# compiler. The VBC and CSC compilers come with the .NET Framework. – Cheeso May 19 '09 at 01:16
  • 2
    You, Sir. You nailed it. +1 for making me browse through my computer to find what I need. – Sina Jun 12 '16 at 08:33
21

Contrary to what some of the other answerers say, you do NOT need the SDK, just the .NET Framework to get the C# compiler, csc.exe.

Also, consider other (free) IDEs like MonoDevelop, #develop, and Visual C# Express. (You said you don't want Visual Studio, not that you don't want an IDE at all ;) )

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
bsneeze
  • 4,369
  • 25
  • 20
14

Latest Microsoft .NET Framework 4.7 doesn't include C# compiler anymore.

But it can be installed as part of standalone MSBuild tool.

Go to https://www.visualstudio.com/downloads/, scroll down to "Other Tools and Frameworks" and choose "Build Tools for Visual Studio 2017".

After "Visual Studio Build Tools 2017" Online Installer runs, switch to "Individual components" tab and check "C# and Visual Basic Roslyn compilers". This would also check MSBuild dependency. All together less than a hundred of megabytes.

The compiler installs at C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Roslyn\csc.exe.

Vadzim
  • 24,954
  • 11
  • 143
  • 151
  • 1
    This is the correct solution at 2020. I'll just note that `msbuild.exe` is not in the same folder, but one up in `Bin` – Jay Jul 14 '20 at 18:07
  • Is that the latest version though? It says version 3.9.0-6.21160.10 which is very old. The one in C:\windows\Microsoft.NET\Framework says version 4.8.4084.0 but that is old too and says there is a newer version. .NET 5.0 was released, where is the csc.exe for that??? – Peter Quiring Apr 08 '21 at 13:03
  • Ok, 3.9 is Roslyn based, while the 4.8 was the old C++ version. This website explains it https://blog.lextudio.com/the-rough-history-of-the-so-many-c-compilers-f3a85500707c – Peter Quiring Apr 08 '21 at 13:18
  • 1
    One correction: "build tools" now under "Tools for Visual Studio" section and it's just stupid web-installer. – Vincent Jan 28 '23 at 12:09
2

Yes, there is even an open source one, IDE SharpDevelop. You can set the compiler as a command in UltraEdit (or some other editor of preference), etc.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dan
  • 11,077
  • 20
  • 84
  • 119
1

I was just looking for a solution like this so that I could just make small console applications using C#.

The method that worked for me was mentioned by Brian, all I did was, after creating my file to simply do:

C:\WINDOWS\Microsoft.NET\Framework\v[your version number]\csc.exe myfile.cs

and it will generate your .exe file that you can then use :)

Carlos F
  • 190
  • 3
  • 10
  • 1
    Typing in the full path every time you want to recompile is not very handy. You can add this path to the PATH env variable and type in `csc.exe myfile.cs` – Pavel Bastov Feb 13 '14 at 06:07
  • I agree with @PavelBastov I just wanted to show the actual path for other users who might want to create an environment variable. – Carlos F Feb 15 '14 at 20:59
1

Assuming you have Visual Studio installed with C# included. Also, assuming you want latest version.

  1. Find the path to your VS installation. Call it VSPath.
  2. The CSC Compiler will be at VSPath\MSBuild(MSBuild-Version)\Bin\Roslyn
JohnTortugo
  • 6,356
  • 7
  • 36
  • 69
  • What a nonsense you're saying! Author asks "deploy a C# compiler without installing Visual Studio". NO VS! – Vincent Jan 28 '23 at 12:11
1

Yes, but you need to download and install .NET Framework SDK.

Here's a link that can help you.

Vadim
  • 21,044
  • 18
  • 65
  • 101
  • 1
    you don't need the sdk, but it does give you the command-line environment which makes building easier – benPearce May 14 '09 at 03:41
1

You only need the .NET framework. You can use Notepad to edit and the CSC.exe to compile.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MRFerocius
  • 5,509
  • 7
  • 39
  • 47
0

Like some others have mentioned MSBuild is deployed with the .NET Framework (versions 2.0 and 3.5) so if you have either of those installed you can build your applications without needing Visual Studio installed on the machine.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Sayed Ibrahim Hashimi
  • 43,864
  • 17
  • 144
  • 178