在新的VS Studio 2017 ASP.NET MVC 5.2.3项目中使用C#7功能时编译错误 [英] Compile errors when using C# 7 features in new VS Studio 2017 ASP.NET MVC 5.2.3 project

查看:172
本文介绍了在新的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(上下文菜单快速操作和重构<封装字段(和use属性)")会引发编译错误.举一个简单的例子:

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:\dev\C#\DummyASPNETMVC\DummyASPNETMVC\Models\Person.cs(12,39,12,41): error CS1043: { or ; expected
1>C:\dev\C#\DummyASPNETMVC\DummyASPNETMVC\Models\Person.cs(12,39,12,41): error CS1513: } expected
1>C:\dev\C#\DummyASPNETMVC\DummyASPNETMVC\Models\Person.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 Tetsuya .这是C#的版本.

Thanks to Panagiotis and Tetsuya. It was the version of c#.

作为对此问题的引用,您必须做三件事:

As a reference to this question, you have to do three things:

  1. 通过Nuget软件包管理器卸载"Microsoft.CodeDom.Providers.DotNetCompilerPlatform",然后重新安装最新版本(当前为1.0.4)
  2. 此后,将Microsoft.Net.Compilers更新到最新版本(当前为2.2.0)
  3. 通过项目属性<构建<高级"将c#语言更改为版本7.

完成.

这篇关于在新的VS Studio 2017 ASP.NET MVC 5.2.3项目中使用C#7功能时编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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