ASP.NET Core Scaffolding does not work in VS 2017
Asked Answered
R

11

19

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

Routine answered 17/7, 2017 at 8:23 Comment(2)
I had an error in my code. When fixed it ran smoothly. (one of my classes was private with an active method)Shipentine
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.Longshore
I
32

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.

Illness answered 5/4, 2018 at 12:42 Comment(0)
J
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

Jeaz answered 30/7, 2017 at 12:8 Comment(2)
What I did is repairing the VS-2017 installation (Enterprise Edition)... And now the scaffolding works.Routine
Preview bits for Microsoft.VisualStudio.Web.CodeGeneration.Design were apparently installed with VS 2019 Preview 3. Downgrading this package to 2.2.3 resolved the issue for me.Marisolmarissa
S
7

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.

Swingletree answered 8/12, 2018 at 9:44 Comment(0)
H
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.

Heedless answered 19/2, 2020 at 10:37 Comment(0)
M
2

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

Malversation answered 30/10, 2019 at 5:28 Comment(1)
where to do that?Longshore
C
2
  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

Cistern answered 8/5, 2021 at 17:45 Comment(0)
R
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

Rosco answered 17/11, 2019 at 14:31 Comment(0)
C
1

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..:-)
Culpa answered 28/10, 2020 at 13:16 Comment(0)
G
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)

Grisgris answered 27/12, 2020 at 9:46 Comment(0)
S
0

go to solution explorer -> clean solution then build solution

this worked for me.

Showroom answered 7/3, 2021 at 5:57 Comment(0)
A
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.

Attila answered 23/4, 2021 at 10:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.