简体   繁体   English

C# 6.0 是否支持 .NET Core,或者 .NET Core 是否响应更高版本的 C#?

[英]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.我刚刚安装了 .NET Core 1.0 并运行了示例 hello world。

  1. Is there any relationship with .NET Core 1.0 and its default C# version?与 .NET Core 1.0 及其默认 C# 版本有任何关系吗?
  2. How can I know the C# version of this .NET Core installation via a command line utility?如何通过命令行实用程序知道此 .NET Core 安装的 C# 版本?

.NET Core 1.0 ships with C# 6. You can see that in the references: .NET Core 1.0 附带 C# 6。您可以在参考资料中看到:

在此处输入图片说明

Microsoft.CodeAnalysis * are the NuGet packages for the C# compiler. Microsoft.CodeAnalysis * 是 C# 编译器的 NuGet 包。 Versions 1.x correspond to C# 6, and 2.x (currently in beta) are C# 7.版本 1.x 对应于 C# 6,而 2.x(目前处于测试阶段)是 C# 7。

You can also see this dependency on NuGet: Microsoft.NETCore.App .您还可以看到对 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.当 C# 7 出现时,可能可以通过将其包添加到 .NET Core 项目来使用新编译器。

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: (例如,由于FormattableString的存在,内插字符串在 .NET 4.6 上比在 .NET 2.0 上更灵活FormattableString 。)但是,有两件事需要考虑:

  • The version of the C# compiler supported by the SDK you've installed ( dotnet cli )您安装的 SDK 支持的 C# 编译器版本 ( dotnet cli )
  • The version of the C# compiler packages that is supported by a particular framework version特定框架版本支持的 C# 编译器包的版本

The SDK supports C# 6 out of the box. SDK 支持开箱即用的 C# 6。 I would personally expect the C# 7 version of the Roslyn packages to support .NET Core as well (eg targeting netstandard1.5 ), so code that compiles more code at execution time should be fine on that front.我个人希望Roslyn 包的 C# 7 版本也支持 .NET Core(例如针对netstandard1.5 ),因此在执行时编译更多代码的代码在这方面应该没问题。 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.我不知道将编译器版本绑定到 SDK 版本方面的计划是什么 - 我怀疑当 project.json 到 msbuild 转换完成时会变得更清楚。

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.我不知道有什么方法可以确定特定 SDK 开箱即用支持哪种语言版本 - 当然,提出一系列小类来执行特定语言功能并查看它们是否可以编译是相当容易的。 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.在连续的语言版本(至少 2-3、3-4、4-5 ......不确定 5-6 之间)之间有一些方法可以做到这一点,但它们稍微复杂一些。

.Net Core和完整的.Net Framework之间的区别更大,意思是,您将能够使用相同的语法,但是您会发现可以/不能使用的类之间存在差异,有时,在方式上你使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM