15

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

serge
  • 9,891
  • 17
  • 84
  • 142
  • I had an error in my code. When fixed it ran smoothly. (one of my classes was private with an active method) – E. G. Mar 23 '20 at 02:44
  • Just don't forget to install Microsoft.VisualStudio.Web.CodeGeneration.Utils. Especially if you are new to this kind of stuff like me. That's what fixed it for me. – André Yuhai May 14 '20 at 22:37

11 Answers11

24

The following works for me.

I deleted bin & obj folders, build the project again and it works.

In case if it gives you error: it couldn't find project.deps.json in debug folder.

Set project to debug, ran it and now you can add scaffolded items.

serge
  • 9,891
  • 17
  • 84
  • 142
Sohail Riaz
  • 256
  • 2
  • 4
10

Clear local NuGet cache with the command from console:

dotnet nuget locals all --clear

Restore all Packages

Install (or update) NuGet package Microsoft.CodeAnalysis.CSharp.Workspaces version 2.0.0 (or higher) EDIT: It seams versions 2.3.0 and 2.3.1 cause some problems. So stick with 2.2.0 at most until MS solves this issues (https://github.com/dotnet/roslyn/issues/20873).

Restore all Packages again and try scaffolding.

That worked for me.

Be sure you have properly referenced these packages in your project:

<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.1" />

<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />

My projects uses Asp.Net Core 1.1.2 and VS2017 Community

AngelDown
  • 271
  • 2
  • 4
6

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.

Andrey Ravkov
  • 712
  • 6
  • 13
5

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.

HockeyJ
  • 13,776
  • 13
  • 82
  • 110
2

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

1

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

1

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)

m nm
  • 11
  • 1
0

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..:-)
0

go to solution explorer -> clean solution then build solution

this worked for me.

0

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.

Will
  • 870
  • 11
  • 11
0
  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