9

I am trying to compile a C# project that someone has created while using C# 6.0 features.

In previous .NET releases, the current C# compiler was automatically installed and ready to run along with the .NET Framework. Apparently, this is no longer the case. I currently have .NET 4.6.1 on my machine, but invoking csc tells me:

Microsoft (R) Visual C# Compiler version 4.6.1055.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

This compiler is provided as part of the Microsoft (R) .NET Framework, but only
supports language versions up to C# 5, which is no longer the latest version. Fo
r compilers that support newer versions of the C# programming language, see http
://go.microsoft.com/fwlink/?LinkID=533240

The link forwards me to the Roslyn project on Github. It does not seem to offer any binary releases.

Curiously, googling for C# 6.0 compiler brings up a couple of discussions on how to add C# 6.0 support to Visual Studio 2013 (with the consensus being more or less that you can't), and countless articles presenting the (admittedly wonderful) new features of C# 6.0, but not a hint on how to obtain a compiler for C# 6.0.

So: How can I get the MS C# 6.0 compiler, and, if required, the necessary build tools such as current versions of MSBuild?

Note that I do not usually have Visual Studio installed, as SharpDevelop seems to be superior for my purposes, so I am wary of installing several gigabytes of data when I already have the framework just to get the up-to-date compiler.

Community
  • 1
  • 1
F-H
  • 663
  • 1
  • 10
  • 21
  • 1
    So you just want the latest [MSBuild](https://www.microsoft.com/en-us/download/details.aspx?id=48159) tools? – DavidG Aug 22 '16 at 22:10
  • 1
    http://stackoverflow.com/questions/32007871/how-to-upgrade-msbuild-to-c-sharp-6 – Alan Aug 22 '16 at 22:10
  • @DavidG: Oh, that's where it's hiding now? :-) Possibly, that's what I'm looking for, yes. – F-H Aug 22 '16 at 22:22
  • @Alan: While related, the other question starts after having installed VS 2015, whereas I'd like to avoid that. – F-H Aug 22 '16 at 22:22
  • @F-H: From the accepted answer: "You can get this version of MsBuild on your system by installing any edition of Visual Studio 2015 or by installing the stand-alone Microsoft Build Tools 2015...Adding a reference to the following NuGet package will also force use of the new compiler:" – Alan Aug 22 '16 at 22:38
  • You just need to install the nuget package https://www.nuget.org/packages/Microsoft.Net.Compilers/ which you can do [without Visual Studio installed](http://stackoverflow.com/questions/13482319/download-nuget-packages-without-vs-nuget-package-manager) – stuartd Aug 22 '16 at 22:39
  • @F-H When you say "hiding", I got that link by Googling for it, it was the top link, that's not very hidden at all... – DavidG Aug 23 '16 at 00:13
  • @DavidG: When I google for "C# 6.0 compiler", the first two results are inquiries on how to enable C# 6.0 in VS2013, followed by an article on what's great about C# 6.0, another text about VS2013 integration, a guide for migrating projects to C# 6.0, and so on. The penultimate result on page 1 is the Roslyn project page, where (as described in the question), it did not seem obvious to me how to find a binary release. After a couple of more articles on new C# 6.0 language features, I finally get a search result to the first actual compiler release - the one on mono-project.com. – F-H Aug 23 '16 at 20:50

1 Answers1

11

From the Roslyn project on GitHub:

To install the latest release without Visual Studio, run one of the following nuget command lines:

nuget install Microsoft.Net.Compilers   # Install C# and VB compilers
nuget install Microsoft.CodeAnalysis    # Install Language APIs and Services

To get the latest "preview" drop, published about once per month, add the -pre switch to the nuget commands.

svick
  • 236,525
  • 50
  • 385
  • 514
WueF
  • 450
  • 8
  • 15
  • 1
    Use 4 spaces at the beginning of a line to format it as code/commands :) – smead Aug 22 '16 at 23:36
  • 6
    And if you are going to quote material from another site word for word (which is the case here), make sure to give proper attribution. – sstan Aug 22 '16 at 23:44
  • Excellent, this sounds helpful. I guess Github is trying to train us to accept a readme file from source control as a website substitute to be read before finding a release, rather than the other way round ;) – F-H Aug 23 '16 at 21:32