(VS2017) There was an error running the selected code generator: 'Sequence contains no elements'

前端 未结 13 2376
忘了有多久
忘了有多久 2021-01-04 11:34

I\'m running through one of Microsoft\'s tutorials on MVC development and I\'m getting errors when trying to create various elements; Views, Controllers, etc.

The e

13条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-04 12:08

    I had this trying to add an Empty API Controller in an ASP.NET Core Web Application (API template). I found in Project Properties the Target Framework wasn't set. I set it to .NET Core 2.1.

    If you then try to add the controller you will get an error because this line of code was added to Startup.cs

    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    

    and CompatibilityVersion doesn't have an enum for Version2_2, so change it to 2_1:

    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    

    and now it adds the controller ok.

    I was getting this with a totally new project. Visual Studio 2017 15.9.11.

    I had already tried the dotnet restore and clearing the ComponentModelCache.

提交回复
热议问题