22

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

But .NET Core which version uses?

Particularly .NET Core 2? C#7?

1
  • 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). Commented Apr 12, 2019 at 6:19

3 Answers 3

20

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

Sign up to request clarification or add additional context in comments.

7 Comments

does it mean if I use VS 2017 15.3 then C#7.1 used for all projects?
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 dontcodetired.com/blog/post/Using-C-71-Features
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 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: github.com/dotnet/roslyn/issues/16717
@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 issue/request.
|
13

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]

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.