Compile errors when using C# 7 features in new VS Studio 2017 ASP.NET MVC 5.2.3 project

二次信任 提交于 2019-12-01 04:18:19

问题


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.

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; }
}

Error message:

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 ==========

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?


回答1:


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

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

  1. Uninstall "Microsoft.CodeDom.Providers.DotNetCompilerPlatform" via Nuget Package Manager and reinstall the newest version (currently the 1.0.4)
  2. After this, update Microsoft.Net.Compilers to the newest version (currently 2.2.0)
  3. Change the c# language via project "properties < build < advanced" to version 7.

done.



来源:https://stackoverflow.com/questions/44383162/compile-errors-when-using-c-sharp-7-features-in-new-vs-studio-2017-asp-net-mvc-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!