ASP.NET Core Scaffolding does not work in VS 2017

Viewed 16592

I have a beginner ASP.NET Core project in Visual Studio 2017, and I am at the scaffolding step of the HelloWorld. The Scaffolding does not work, I tested on a first computer, then at a second one...

when I try to generate a controller with views enter image description here , it gives the following error on the first machine:

Microsoft Visual Studio


Error

There was an error running the selected code generator:

'Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Web.CodeGeneration.Utils, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.Main(String[] args)'


OK

On the second machine:

Microsoft Visual Studio


Error

There was an error running the selected code generator:

'Error: assembly specified in the dependencies manifest was not found -- package: 'microsoft.applicationinsights.aspnetcore', version: '2.1.0', path: 'lib/netstandard1.6/Microsoft.ApplicationInsights.AspNetCore.dll''


OK

11 Answers

I has the same situation. On .net core version 2.2 and with VS 2017 Enterprise.

The next instruction hepls for me:

  • open VS with Admin rights.
  • load solution to VS
  • add controller from scaffolding menu. VS will install 'Microsoft.VisualStudio.Web.CodeGeneration.Design' and 'Microsoft.VisualStudio.Web.CodeGeneration.Tools' packages.
  • close VS
  • open VS and load project. Add controllers via scaffloading is working fine

Maybe this instruction helps somebody, Thanks.

For the benefit of searchers:

I got this in VS2019. The cause was that my code was broken.

Didn't realise why to start, but when you realise that code generation is a nuget package; if the project doesn't build, then Visual Studio can't get to that package.

Once I got the code compiling, this error went away.

you should change the version of Microsoft.VisualStudio.Web.CodeGeneration.Design exactly like the version of Microsoft.AspNetCore.App

  1. On menu --> Compile --> Clean Solution
  2. On menu --> Compile --> Build Solution.

Then repeat de creation of crud using scaffolding. That works for me. Thanks

I was trying to run the command bellow with the version 3.0.0 of asp.net core installed, so I got the same error Command: dotnet aspnet-codegenerator controller -name MoviesController -m Movie -dc MvcMovieContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries

Error: Scaffolding failed. Could not load file or assembly 'Microsoft.VisualStudio.Web.CodeGeneration, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

  • Solution:

dotnet nuget locals all --clear

dotnet remove package Microsoft.VisualStudio.Web.CodeGeneration.Utils

Change the PackageRefere for the version 2.2.0

Run the command again. dotnet aspnet-codegenerator controller -name MoviesController -m Movie -dc MvcMovieContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries

Solution:

  1. Go to VS2019 --> Dependencies -->Packages
  2. Click on Manage NuGet
  3. In the search type "Microsoft.VisualStudio.Web.CodeGeneration.Utils" or the Dll that is missing.
  4. Click Install.
  5. Rebuild the solution
  6. Then add the Scaffolding item. It works..:-)

I fixed this by uninstalling all entity framework packages using nuget package manager and again reinstall with same version.

  • Microsoft.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.Design
  • Microsoft.EntityFrameworkCore.SqlServer

(3.10 version)

go to solution explorer -> clean solution then build solution

this worked for me.

I was receiving different error messages. Actually there was nothing specific, no mention of dependencies or assemblies. I tried all of the above suggestions with no success. Then I tried letting it create a new DbContext instead of specifying an existing one. That resolved my issue.

Related