dotnet / Scaffolding

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

Identity MVC scaffolding does utilize scaffolded assets #2973

Open MackinnonBuck opened 2 weeks ago

MackinnonBuck commented 2 weeks ago

Summary

When scaffolding Identity UI into a project without an existing _Layout.cshtml, the scaffolder (dotnet aspnet-codegenerator identity) doesn't generate links pointing to the scaffolded assets in the project. Instead, it points to the assets provided by the Microsoft.AspNetCore.Identity.UI package.

Steps to reproduce

  1. Create a new ASP.NET Core Web API App (dotnet new webapi)
  2. Add the necessary packages to the project:
    dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
    dotnet add package Microsoft.EntityFrameworkCore.Design
    dotnet add package Microsoft.AspNetCore.Identity.EntityFrameworkCore
    dotnet add package Microsoft.AspNetCore.Identity.UI
    dotnet add package Microsoft.EntityFrameworkCore.SqlServer
    dotnet add package Microsoft.EntityFrameworkCore.Tools
  3. Run the scaffolder:
    dotnet aspnet-codegenerator identity

    NOTE: The --useDefaultUI flag is intentionally excluded here

  4. Add the following lines to Program.cs:
    builder.Services.AddRazorPages();
    // ...
    var app = builder.Build();
    // ...
    app.MapStaticAssets();
    app.MapRazorPages()
        .WithStaticAssets();

    💭 Thought: Maybe these changes should be included by the scaffolder as well? 💭

  5. Make a trivial edit to one of the scaffolded assets (e.g., add a comment in bootstrap.css)
  6. Run the app, and navigate to the /identity/account/login page
  7. Look at the sources tab, and notice that the loaded assets don't include the edit made in step 5.

Expected behavior

When not specifying the --useDefaultUI option, the links in _Layout.cshtml should point to scaffolded assets, not assets in the Microsoft.AspNetCore.Identity.UI package.

Actual behavior

Each resource link in _Layout.cshtml has an ~/Identity prefix, which causes the assets to be loaded from Microsoft.AspNetCore.Identity.UI.