identityblazor-server-side.net-5asp.net-core-scaffolding

Scaffold Identity fails in .Net5 Blazor Server


I have an existing .Net 5 Blazor Server application. No authentication or authorization at this point. I am attempting to add Microsoft Identity via scaffolding but continue to get the the following error when I attempt to scaffold Identity into the project which I can not resolve "There was an error in the selected code generator 'Package restore failed. Rolling back package changes [MySolujtionName] Server."

Thing's I have tried:

So far no luck and I continue to get the same error.


Solution

  • I've tried with a new Blazor Server project and it works with:

    1. Specify at least one override (I've selected Login, Logout and Registration)
    2. Specify the full path of the _Layout.cshtml (I've used /Areas/Identity/Pages/Account/Manage/_Layout.cshtml)
    3. Add a Context
    4. Add a User model

    then the scaffolding works as expected.

    I obtain the following structure:

    enter image description here

    The User model class generated by the scaffolder will be:

    namespace Test2.Areas.Identity.Data
    {
        // Add profile data for application users by adding properties to the Test2User class
        public class Test2User : IdentityUser
        {
        }
    }
    

    UPDATE

    I've found a bug in the Visual Studio Generator.
    The only possibility to scaffold the Identity pages from an existing project is to execute the scaffolding process via command line.

    Here is an example of the command line:

    dotnet aspnet-codegenerator identity -dc TestWasmAuthIndividual.Server.Data.ApplicationDbContext --files "Account.Register;Account.Login;Account.Logout;Account.Manage.PersonalData" --force
    

    you need to execute this command line from the Server project.