Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C# 6.0 support .NET Core, or does .NET Core respond to higher version of C#?

I've just installed .NET Core 1.0 and run the sample hello world.

  1. Is there any relationship with .NET Core 1.0 and its default C# version?
  2. How can I know the C# version of this .NET Core installation via a command line utility?
like image 392
Hind Forsum Avatar asked Dec 24 '22 03:12

Hind Forsum


2 Answers

.NET Core 1.0 ships with C# 6. You can see that in the references:

enter image description here

Microsoft.CodeAnalysis* are the NuGet packages for the C# compiler. Versions 1.x correspond to C# 6, and 2.x (currently in beta) are C# 7.

You can also see this dependency on NuGet: Microsoft.NETCore.App.

When C# 7 comes out, it would probably be possible to use the new compiler by adding its package to a .NET Core project.

like image 73
Eli Arbel Avatar answered Jan 25 '23 23:01

Eli Arbel


The language itself isn't generally tied to a specific runtime/framework, although some language features do require framework features. (For example, interpolated strings are a bit more flexible on .NET 4.6 than on .NET 2.0 due to the presence of FormattableString.) However, there are two things to consider:

  • The version of the C# compiler supported by the SDK you've installed (dotnet cli)
  • The version of the C# compiler packages that is supported by a particular framework version

The SDK supports C# 6 out of the box. I would personally expect the C# 7 version of the Roslyn packages to support .NET Core as well (e.g. targeting netstandard1.5), so code that compiles more code at execution time should be fine on that front. I don't know what the plan is in terms of tying compiler versions to SDK versions - I suspect that will become clearer when the project.json to msbuild transition is complete.

I don't know of any way of determining what language version a particular SDK supports out of the box - it would be reasonably easy to come up with a sequence of small classes which exercise particular language features and see if they compile, of course. Trickier would be to come up with code that builds with multiple versions but gives different results; there are ways of doing that between consecutive language versions (at least 2-3, 3-4, 4-5... not sure about 5-6) but they're slightly more convoluted.

like image 45
Jon Skeet Avatar answered Jan 25 '23 23:01

Jon Skeet