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
Visual Studio 2019 and .net core 3.0
Uninstalled: Microsoft.VisualStudio.Web.CodeGeneration.Design Version: 3.1.0-preview3.19558.8
and Installed: Microsoft.VisualStudio.Web.CodeGeneration.Design Version: 3.0.0
Solved the issue for me.
Uninstalling and reinstalling VS2017 did not work. I can create classes, items and other lesser elements. However, the issues with creating Controllers, View, etc. persists.
I've upvoted @James's comment because it worked for me, but I wanted to add it as an answer to make it more visible to others:
Open the package manager console:
Tools > Nuget Package Manager > Package Manager Console
Type:
dotnet restore
No restart / reinstall required.
Error will occur if you had different instances of connection strings in your web.config
Comment out the other not needed or necessary connection strings tags then rebuild your solution. That would be all
My project had a warning against one of the dependancies (Microsoft.VisualStudio.Web.CodeGeneration.Design). I removed that dependancy and then rebuilt the project.
I then added a new Razor page and the dependancy was readded to the project - with an earlier version (2.1.9) and I can now add Razor pages without issue.
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.