dotnet / Scaffolding

Code generators to speed up development.
MIT License
640 stars 228 forks source link

Scaffold Identity in "dotnet new Angular" app gives error: "error running the selected code generator" #1516

Open johnpankowicz opened 3 years ago

johnpankowicz commented 3 years ago

Describe the bug

Scaffold Identity in a new app, created with "dotnet new angular --auth Individual", immediately throws an error:

"There was an error running the selected code generator:
'Package restore failed. Rolling back package changes for `'aspangauth'.'

To Reproduce

  1. Run: "dotnet new angular --auth Individual"

  2. Open the project in Visual Studio 2019 ( I am using Version 16.9.0 Preview 2.0)

  3. Select: Add -> New Scaffolded Item

  4. Choose "Identity"

  5. Either leave the "Existing layout page" box blank or enter: ~/Pages/Shared/_Layout.cshtml

(Unlike an app created with "dotnet new webapp --auth Individual", the new SPA app does not have a _Layout.cshtml file. What should be entered here?)

  1. Choose some files to override. (I chose Account\Login, Account\Logout, Account\Register and Account\RegisterConfirmation. I also tried just choosing Account\Login.)

  2. Set the Data context class to ApplicationDbContext.

  3. Select "Add". You should immediately get the error.

Scaffold Identity works fine for me if I create an app with "dotnet new webapp --auth Individual". On stackoverflow, it was suggested to change the version of "Microsoft.VisualStudio.Web.CodeGeneration.Design". I tried changing from 5.0.1 to 5.0.0 and also 3.1.1. All gave the same error.

Is there an alternate way to scaffold these files?

Besides using the VS user interface, is there a manual way of overriding the files that are needed? Can I just copy files from the ones I get when I scaffold a webapp instead of an angular app?

The document "Scaffold Identity in ASP.NET Core projects" does not contain instructions for a Asp.Net SPA project.

Exceptions (if any)

Popup box with error:

"There was an error running the selected code generator:
'Package restore failed. Rolling back package changes for `'aspangauth'.'

Further technical details

Output of dotnet --info

.NET SDK (reflecting any global.json): Version: 5.0.200-preview.20601.7 Commit: b3b934bbf2

Runtime Environment: OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.200-preview.20601.7\

Host (useful for support): Version: 5.0.0 Commit: cf258a14b7

.NET SDKs installed: 1.0.0-preview2-003131 [C:\Program Files\dotnet\sdk] 1.0.3 [C:\Program Files\dotnet\sdk] 1.0.4 [C:\Program Files\dotnet\sdk] 2.0.0 [C:\Program Files\dotnet\sdk] 2.0.2 [C:\Program Files\dotnet\sdk] 2.0.3 [C:\Program Files\dotnet\sdk] 2.1.1-preview-007118 [C:\Program Files\dotnet\sdk] 2.1.2 [C:\Program Files\dotnet\sdk] 2.1.4 [C:\Program Files\dotnet\sdk] 2.1.103 [C:\Program Files\dotnet\sdk] 2.1.104 [C:\Program Files\dotnet\sdk] 2.1.200-preview-007474 [C:\Program Files\dotnet\sdk] 2.1.200 [C:\Program Files\dotnet\sdk] 2.1.201 [C:\Program Files\dotnet\sdk] 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.300 [C:\Program Files\dotnet\sdk] 2.1.400 [C:\Program Files\dotnet\sdk] 2.1.502 [C:\Program Files\dotnet\sdk] 2.1.504 [C:\Program Files\dotnet\sdk] 2.1.505 [C:\Program Files\dotnet\sdk] 2.1.507 [C:\Program Files\dotnet\sdk] 2.1.508 [C:\Program Files\dotnet\sdk] 2.1.515 [C:\Program Files\dotnet\sdk] 2.1.800-preview-009696 [C:\Program Files\dotnet\sdk] 2.2.105 [C:\Program Files\dotnet\sdk] 2.2.109 [C:\Program Files\dotnet\sdk] 2.2.207 [C:\Program Files\dotnet\sdk] 3.0.103 [C:\Program Files\dotnet\sdk] 3.1.402 [C:\Program Files\dotnet\sdk] 5.0.200-preview.20601.7 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

mkArtakMSFT commented 3 years ago

Thanks for contacting us.

@vijayrkn can you please take a look at this? Thanks!

mkArtakMSFT commented 3 years ago

Ping @vijayrkn

vijayrkn commented 3 years ago

Adding @deepchoudhery

wildough57 commented 3 years ago

This was driving me a little mad. Finally I let it create a new dbcontext instead of specifying an existing one and everything ran successfully to completion. And BTW, the existing one that I was trying to specify was a direct copy of one scaffolded into another project.

johnpankowicz commented 3 years ago

This was driving me a little mad. Finally I let it create a new dbcontext instead of specifying an existing one and everything ran successfully to completion.

@wildough57 How were you able to do that? The "Add" button in the dialog box is not active until a dbcontext is specified.

wildough57 commented 3 years ago

@johnpankowicz Just give it a new name or accept the one it prompts with.  Anything besides an existing DbContext.

johnpankowicz commented 3 years ago

@wildough57 That does not work for me. I tried:

Are you using ""dotnet new angular --auth Individual" to create the project? Because, as I say in the post, "dotnet new webapp --auth Individual" works fine.

iwannabebot commented 3 years ago

Any update on this?

maxima120 commented 3 years ago

I have same issue and I am convinced that it has to do with dll versions. I had this before in another project with lower core .net version (I think it was 5.0.3). I cant tell for sure but upgrading did work somehow.

Now I have new app in 5.0.7 and I cant scaffold the identity (trying to create new dbContext as suggested above - doesnt help either).

One thing however springs to attention: every time I try to scaffold (and fail) - I have 2 nugets downgraded to 5.0.6 (somehow during the scaffolding attempt):

Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.SqlServer

NOTE: I use SQLite in the app, so I dont know where the SqlServer is coming at all

maxima120 commented 3 years ago

Whats has worked:

claybrooks commented 3 years ago

The auto downgrade of Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameWorkCore.Tools to 5.0.6 from 5.0.7 happened for me as well. I downgraded Microsoft.AspNetCore.ApiAuthorization.IdentityServer to 5.0.6 with the other two at 5.0.6 and re-ran the scaffolding without issue.

deepchoudhery commented 3 years ago

Hey, I'll have updates for the issue here very soon - https://github.com/dotnet/Scaffolding/issues/1555. Pretty much the same issue. @claybrooks @maxima120.

Thanks.

huynguyen120390 commented 2 years ago

Manual updating has issues about dependencies. I manually removed and upgraded all EntityFrameworkCore-related packages to 5.0.12, because I noticed Scaffolding auto changed my EntityFrameworkCore.SqlServer to 5.0.12. Things were smooth after that. One thing, it wants me to install EntityFrameworkCore.Identity.UI on a different project where I store my AppDbContext class.

mleziva commented 2 years ago

When I start with an Angular project using .NET 5 and select individual authentication at creation time, then I am still seeing the same error with version 5.0.2 of Microsoft.VisualStudio.Web.CodeGeneration.Design

However, I am able to successfully run the scaffolding for identity if I don't select individual auth when I create the project.

A potential workaround is to create the scaffolding using a temporary no individual auth project and then copy the required files to your working project and update the names

ShariirahS commented 2 years ago

I started a new MVC Angular project with VS2022 and no more thins to do and I received 12 errors at start.

Error TS6053 File 'C:/Users/shahr/Desktop/Project2/ClientApp/node_modules/source-map-js/source-map' not found. The file is in the program because: Root file specified for compilation Project2 JavaScript Content Files 1 Active Error TS6053 File 'C:/Users/shahr/Desktop/Project2/ClientApp/node_modules/agent-base/dist/src/index' not found. The file is in the program because: Root file specified for compilation Project2 JavaScript Content Files 1 Active Error TS6053 File 'C:/Users/shahr/Desktop/Project2/ClientApp/node_modules/https-proxy-agent/dist/index' not found. The file is in the program because: Root file specified for compilation Project2 JavaScript Content Files 1 Active Error TS6053 File 'C:/Users/shahr/Desktop/Project2/ClientApp/node_modules/jsonc-parser/lib/umd/main' not found. The file is in the program because: Root file specified for compilation Project2 JavaScript Content Files 1 Active Error TS6053 File 'C:/Users/shahr/Desktop/Project2/ClientApp/node_modules/socks-proxy-agent/dist/index' not found. The file is in the program because: Root file specified for compilation Project2 JavaScript Content Files 1 Active Error TS1010 (TS) '/' expected. Project2 JavaScript Content Files C:\Users\shahr\Desktop\Project2\ClientApp\node_modules\@types\node\inspector.d.ts 2549 Active Error TS1110 (TS) Type expected. Project2 JavaScript Content Files C:\Users\shahr\Desktop\Project2\ClientApp\node_modules\commander\typings\index.d.ts 242 Active Error TS1010 (TS) '/' expected. Project2 JavaScript Content Files C:\Users\shahr\Desktop\Project2\ClientApp\node_modules\jest-worker\build\types.d.ts 50 Active Error TS1005 (TS) '}' expected. Project2 JavaScript Content Files C:\Users\shahr\Desktop\Project2\ClientApp\node_modules\magic-string\index.d.ts 81 Active Error TS1010 (TS) '*/' expected. Project2 JavaScript Content Files C:\Users\shahr\Desktop\Project2\ClientApp\node_modules\reflect-metadata\index.d.ts 241 Active