Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core Scaffolding does not work in VS 2017

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

like image 773
serge Avatar asked Jul 17 '17 08:07

serge


2 Answers

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.

like image 169
Sohail Riaz Avatar answered Oct 16 '22 04:10

Sohail Riaz


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

like image 45
AngelDown Avatar answered Oct 16 '22 04:10

AngelDown