Pavel Bastov
Pavel Bastov

Reputation: 6971

Is it possible to install a C# compiler without Visual Studio?

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

Upvotes: 77

Views: 98830

Answers (11)

ascpixi
ascpixi

Reputation: 607

The other answers only describe the legacy, closed-source .NET Framework - for the modern open-source .NET, you can find the csc assembly under <SDK location>/Roslyn/bincore/csc.dll. For example:

asc@ascpixi:~$ dotnet --list-sdks
8.0.107 [/usr/lib/dotnet/sdk]
asc@ascpixi:~$ dotnet exec /usr/lib/dotnet/sdk/8.0.107/Roslyn/bincore/csc.dll -version
4.8.0-7.24225.6 (de75b3c7)

However, if you simply want to use csc from the command-line, you can try the dotnet tool:

dotnet tool install -g csc

...which will allow you to use csc as any other command line utility.

asc@ascpixi:~$ csc -version
4.8.0-7.24225.6 (de75b3c7)

Upvotes: 0

Sayed Ibrahim Hashimi
Sayed Ibrahim Hashimi

Reputation: 44342

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.

Upvotes: 0

lc.
lc.

Reputation: 116528

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.

Upvotes: 48

Vadzim
Vadzim

Reputation: 26210

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.

Upvotes: 15

bsneeze
bsneeze

Reputation: 4479

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 ;) )

Upvotes: 21

Dan
Dan

Reputation: 11183

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.

Upvotes: 2

MRFerocius
MRFerocius

Reputation: 5629

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

Upvotes: 1

Brian
Brian

Reputation: 118925

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.

Upvotes: 35

CAJOGOS
CAJOGOS

Reputation: 190

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 :)

Upvotes: 1

Matthew Flaschen
Matthew Flaschen

Reputation: 285047

Of course. Do:

sudo apt-get install mono-gmcs

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

Upvotes: 47

Vadim
Vadim

Reputation: 21724

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

Here's a link that can help you.

Upvotes: 1

Related Questions