dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.44k stars 10.02k forks source link

Scaffolded Identity pages not overriding default implementation #55312

Open astrassburg opened 6 months ago

astrassburg commented 6 months ago

Is there an existing issue for this?

Describe the bug

When creating a new ,net8 ASP.NET Core Web App (Razor Pages) project with individual account authentication and then scaffolding identity pages, any changes or breakpoints made in the scaffolded pages are not reflected / hit in the application.

This is a recent issue and is now affecting all of my projects using asp.net Identity on .net8.

Expected Behavior

The Scaffolded Identity pages in the project should be used by the application instead of the default identity views.

Steps To Reproduce

  1. Create a new ASP.NET Core Web App (Razor Pages) project in Visual Studio 2022 (v17.8.7)
  2. Select Framework .NET 8.0 (Long Term Support)
  3. Select Authentication type Individual Accounts
  4. Right click the project in solution explorer and choose Add -> New Scaffolded Item...
  5. Select Identity on the left hand list and click Add.
  6. Select a view to override: Account/Login
  7. Select ApplicationDbContext in the DbContext class dropdown and click Add.
  8. Change the <h2> on line 13 of /Areas/Identity/Pages/Account/Login.cshtml to hello world!
  9. Set a breakpoint on line 89 of /Areas/Identity/Pages/Account/Login.cshtml.cs
  10. Add NuGet package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
  11. Change line 18 of Program.cs to builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
  12. Build -> Rebuild Solution
  13. Run the app using Kestrel and navigate to the Login view at /Identity/Account/Login.
  14. Observe that the breakpoint in Login.cshtml.cs is not hit and the <h2> tag is not modified from the default value.

Exceptions (if any)

None.

.NET Version

8.0.204

Anything else?

VS version: Microsoft Visual Studio Enterprise 2022 (64-bit) - Current Version 17.8.7

.NET SDK: Version: 8.0.204 Commit: c338c7548c Workload version: 8.0.200-manifests.9851afd8

Runtime Environment: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.204\

.NET workloads installed: There are no installed workloads to display.

Host: Version: 8.0.4 Architecture: x64 Commit: 2d7eea2529

.NET SDKs installed: 5.0.408 [C:\Program Files\dotnet\sdk] 8.0.100-preview.7.23376.3 [C:\Program Files\dotnet\sdk] 8.0.102 [C:\Program Files\dotnet\sdk] 8.0.104 [C:\Program Files\dotnet\sdk] 8.0.204 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0-preview.7.23375.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0-preview.7.23375.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0-preview.7.23376.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

astrassburg commented 6 months ago

Public repro repo here: https://github.com/astrassburg/sc-repro

SteveSandersonMS commented 6 months ago

We notice that the steps to reproduce include AddRazorRuntimeCompilation. Can you confirm this step is required in order for the bug to occur?

astrassburg commented 6 months ago

We notice that the steps to reproduce include AddRazorRuntimeCompilation. Can you confirm this step is required in order for the bug to occur?

Hello @SteveSandersonMS -

Without the AddRazorRuntimeCompilation() change, I am unable to run the project in either Kestrel or IISExpress. All routes return either 404 or a missing partial view error. It seems this could be related to the problem.

astrassburg commented 6 months ago

Some further investigation:

Running the following from Visual Studio 2022:

Build -> Clean Solution Build -> Rebuild Solution

In Release configuration produces an sc-repro.dll of 53kiB.

Running from the command line instead:

dotnet clean --configuration Release
dotnet build --configuration Release

produces an sc-repro.dll of 137kiB which works. This indicates that views are being compiled in via dotnet but being skipped for some reason in Visual Studio.