21

I know that C# version depends on .NET Framework.

But .NET Core which version uses?

Particularly .NET Core 2? C#7?

svick
  • 214,528
  • 47
  • 357
  • 477
Alexan
  • 6,893
  • 13
  • 69
  • 89
  • I hope you have just been imprecise with your words. The C# version and. NET version are almost independent from each other: I could compile code written in C#7.2 with .NET3.5 and code in C#3 with .NET4.7.2. What you can do depends mostly on the Visual Studio version (And therefore: The compiler). – Robert Tausig Apr 12 '19 at 06:19

3 Answers3

20

.NET Core 2.0 references Roslyn 2.3, which corresponds to Visual Studio 2017 version 15.3 and supports C# 7.1.

Julien Couvreur
  • 3,615
  • 25
  • 37
  • does it mean if I use VS 2017 15.3 then C#7.1 used for all projects? – Alexan Aug 27 '17 at 04:57
  • 4
    Each project has a LangVersion setting, which is "default" by default, which means "latest major version" (C# 7.0 in this case). If you want to use a minor version, such as C# 7.1, you'll have to change that setting. More information at http://dontcodetired.com/blog/post/Using-C-71-Features – Julien Couvreur Aug 27 '17 at 05:06
  • The file you linked to says that the version of Roslyn used is 2.3.0-beta3-61816-04. I don't think that's right: the release version of .Net Core shouldn't be using beta version of Roslyn. – svick Aug 27 '17 at 14:25
  • @svick This was apparently done intentionally for this release of Core. It's ok because Core redistributes/copies the compiler binaries. That said, a better design will be put in place soon. I'm not sure which issue tracks this, but I think it's related to this work: https://github.com/dotnet/roslyn/issues/16717 – Julien Couvreur Aug 28 '17 at 19:28
  • Can I check supported c# versions via dotnet cli ? Is there any roadmap for c# lang support in dotnet core ? – tpx86 Feb 21 '18 at 17:47
  • 1
    @tpx86 I don't think there is a convenient way to see what version of the C# compiler or what language versions it supports from dotnet cli. The best I found on my box is something like: `dotnet exec "c:\Program Files\dotnet\sdk\2.2.0-preview1-007622\Roslyn\bincore\csc.dll" -langversion:?`. That could be a worthwhile [cli](https://github.com/dotnet/cli) issue/request. – Julien Couvreur Feb 25 '18 at 05:45
  • `dontnet --info` gives you the SDK version from which you can determine which versions of C# are supported. – Shane Jul 04 '19 at 01:05
11

The C# what's new version history page gives a list of all versions plus their associated Visual Studio and .NET core version:

  • C# 7.3 Visual Studio 2017 version 15.7, and in the .NET Core 2.1 SDK 2.1.300 RC1
  • C# 7.2 Visual Studio 2017 version 15.5, and in the .NET Core 2.0 SDK.
  • C# 7.1 Visual Studio 2017 version 15.3, and in the .NET Core 2.0 SDK.
  • C# 7.0 Visual Studio 2017 and .NET Core 1.0 and later

C# 8.0 is still in preview at this time (3-Jul-2019).

You can also see your SDK version with this command:

dotnet --info

Sample output:

.NET Core SDK (reflecting any global.json):
 Version:   2.1.300
 Commit:    adab45bf0c

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.13
 OS Platform: Darwin
 RID:         osx.10.13-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.1.300/

Host (useful for support):
  Version: 2.1.0
  Commit:  caa7b7e2ba

.NET Core SDKs installed:
  2.1.300 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Shane
  • 4,108
  • 1
  • 32
  • 33
3

From Microsoft .net core what's new page:

NET Core 2.0 supports C# 7.1, which adds a number of new features, including:

  • The Main method, the application entry point, can be marked with the async keyword.
  • Inferred tuple names.
  • Default expressions.

You can also review check the C# Language versioning page

The compiler determines a default based on these rules:

.NET Core 2.x C# 7.3

Community
  • 1
  • 1
Jonathan Ramos
  • 1,255
  • 13
  • 17