如何在 Visual Studio 2017 项目中启用 C# 7 的所有功能? [英] How can I enable all features of C# 7 in Visual Studio 2017 project?

查看:49
本文介绍了如何在 Visual Studio 2017 项目中启用 C# 7 的所有功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio 2017 发布后,我想尝试使用新的 C# 7 功能创建简单的控制台项目.我希望我只需下载新的 Visual Studio 2017,然后创建新的控制台项目并可以使用新的 C# 7 功能.但我不能.

After Visual Studio 2017 was released I wanted to try to create simple console project with new C# 7 features. I expected that I simply download new Visual Studio 2017, then create new console project and can use new C# 7 features. But I can't.

如果我安装 NuGet,我可以使用一些功能,例如元组包 System.ValueTuple.

但是对于其他功能,我不知道我需要做什么.例如 这个 NuGet 问题.

But for other features, I don't know what I need to do. For example this NuGet issue.

我现在需要进行所有这些肮脏的安装吗?或者我可以以更简单的方式启用 c# 7 功能?

Do I need to do all this dirty install now? Or I can enable c# 7 features in a more simple way?

推荐答案

对于您在问题的第二部分链接到的任意类似任务的类型,您需要包含 System.Threading.Tasks.Extensions 包.

For arbitrary task-like types you linked to in the 2nd part of your question you need to include the System.Threading.Tasks.Extensions package.

您需要这些 NuGet 包的原因是因为新语言功能依赖于添加到 .NET 框架的新类型.C# 语言特性所依赖的新类型将不会内置到框架中",直到 4.6.2 之后发布的下一个小版本才不会破坏 SemVer1.因此,除非您使用该框架的下一个版本构建项目,否则您将需要使用 NuGet 包来使这些功能正常工作.

The reason you need these NuGet packages is because the new language features rely on new types added to the .NET framework. The new types that the C# language features depend on will not be "built in to the framework" until the next minor version released after 4.6.2 to not break SemVer1. So unless you are building a project using that next version of the framework you will need to use the NuGet packages to get the features to work.

这个与让扩展方法在 .NET 2.0 项目中工作没有什么不同.您可以使用扩展方法,但您需要使用 NuGet 包(或自己添加代码)来获取它所依赖的类型以添加​​到您的项目中.

This is no different than getting extension methods to work in a .NET 2.0 project. You can use extension methods but you need to use a NuGet package (or add the code yourself) to get the types it relies on to be added to your project.

1:所以 4.7 或 5.0,无论他们决定如何称呼它,如果有 4.6.3,它就不会出现在那个版本中,因为这不是次要版本版本的提升,而是补丁版本的提升并且您不能在不违反语义版本控制的情况下在补丁版本提升中进行 API 更改.

这篇关于如何在 Visual Studio 2017 项目中启用 C# 7 的所有功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆