Compile errors when using C# 7 features in new VS Studio 2017 ASP.NET MVC 5.2.3 project(在新的 VS Studio 2017 ASP.NET MVC 5.2.3 项目中使用 C# 7 功能时出现编译错误)
问题描述
我通常将 VS 2017 用于控制台应用程序.但是现在我必须创建一个新的 ASP.NET MVC 项目并发现了一些奇怪的东西.
I'm using VS 2017 usually for console applications. But now I have to create a new ASP.NET MVC project and found something curious.
自动生成 getter 和 setter(上下文菜单快速操作和重构 < 封装字段(和使用属性)")引发编译错误.举个简单的例子:
Auto generation of getter and setter (context menu "Quick actions and refactoring < Ecapsulate field (and use property)") raise a compiling error. To give an easy example:
public class Person
{
private string firstname;
public string Firstname { get => firstname; set => firstname = value; }
}
错误信息:
1>------ Build started: Project: DummyASPNETMVC, Configuration: Debug Any CPU ------
1>C:devC#DummyASPNETMVCDummyASPNETMVCModelsPerson.cs(12,39,12,41): error CS1043: { or ; expected
1>C:devC#DummyASPNETMVCDummyASPNETMVCModelsPerson.cs(12,39,12,41): error CS1513: } expected
1>C:devC#DummyASPNETMVCDummyASPNETMVCModelsPerson.cs(14,2,14,2): error CS1513: } expected
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
取消注释 getter 和 setter 将使事情再次工作.
Uncomment the getter and setter will make the things working again.
我想知道,因为这在控制台应用程序中运行良好.这里的区别在哪里?
I'm wondering because this works fine within a console application. Where's the difference here?
推荐答案
感谢 Panagiotis 和 哲也.那是c#的版本.
Thanks to Panagiotis and Tetsuya. It was the version of c#.
作为这个问题的参考,你必须做三件事:
As a reference to this question, you have to do three things:
- 通过 Nuget 包管理器卸载Microsoft.CodeDom.Providers.DotNetCompilerPlatform"并重新安装最新版本(当前为 1.0.4)
- 在此之后,将 Microsoft.Net.Compilers 更新到最新版本(当前为 2.2.0)
- 通过项目properties < build < advanced"将 c# 语言更改为版本 7.
完成.
这篇关于在新的 VS Studio 2017 ASP.NET MVC 5.2.3 项目中使用 C# 7 功能时出现编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在新的 VS Studio 2017 ASP.NET MVC 5.2.3 项目中使用 C# 7 功能时出现编译错误


基础教程推荐
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01