dotnet / project-system

The .NET Project System for Visual Studio
MIT License
969 stars 387 forks source link

Deleting a component in a BWA doesn't remove it from rendering when rerunning the app in VS #9317

Open guardrex opened 1 year ago

guardrex commented 1 year ago

Is there an existing issue for this?

Describe the bug

Deleting a component in a BWA doesn't remove it from rendering when rerunning the app in VS.

Expected Behavior

Deleting the component and running the app again shouldn't still permit accessing/using the component.

Steps To Reproduce

  1. Create a BWA from the RC1 template.
  2. Add the following Components/Pages/Counter2.razor component to the server project:
@page "/counter-2"
@attribute [RenderModeServer]

<PageTitle>Counter 2</PageTitle>

<h1>Counter 2</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount++;
    }
}
  1. Run the app. Navigate to /counter-2 to confirm it renders interactively.
  2. Stop the debugger.
  3. Delete the Counter2 component from the Components/Pages folder.
  4. Rerun the app with the debugger.
  5. Navigate to /counter-2 in the browser.

The Counter2 component still renders interactively.

  1. Stop the debugger.
  2. Clean the solution.
  3. Rerun the app.
  4. Navigate to /counter-2 in the browser.

The Counter2 component is gone.

Exceptions (if any)

None

.NET Version

8.0.100-rc.1.23455.8

Anything else?

.NET SDK: Version: 8.0.100-rc.1.23455.8 Commit: e14caf947f

Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.100-rc.1.23455.8\

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

Host: Version: 8.0.0-rc.1.23419.4 Architecture: x64 Commit: 92959931a3 RID: win-x64

.NET SDKs installed: 3.1.426 [C:\Program Files\dotnet\sdk] 5.0.214 [C:\Program Files\dotnet\sdk] 6.0.317 [C:\Program Files\dotnet\sdk] 7.0.111 [C:\Program Files\dotnet\sdk] 8.0.100-preview.7.23376.3 [C:\Program Files\dotnet\sdk] 8.0.100-rc.1.23455.8 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] 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.22 [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.11 [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.0-rc.1.23421.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.15 [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.22 [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.11 [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.0-rc.1.23419.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.15 [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.22 [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.11 [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.0-rc.1.23420.5 [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

javiercn commented 1 year ago

@guardrex thanks for reporting this.

This likely looks like an up-to-date check issue in Razor, since likely VS thinks the assembly is up to date and doesn't need to rebuild it.

chsienki commented 1 year ago

@jjonescz PTAL and see if you can repro, thanks!

jjonescz commented 1 year ago

Yes, can repro in VS 17.8 Preview 5 with RC2 and 8.0.100-rtm.23506.1. Looks like an issue for @dotnet/razor-tooling - the project is not built at all after the component is deleted. If you change something else apart from deleting the component (e.g., a line of code), the project is rebuilt and the component is removed properly.

davidwengier commented 1 year ago

Razor tooling, in general, is not involved in build. If its a fast up to date check issue, then its probably something missing from the Razor SDK props or targets files, or a change in the project template that violates some assumption they make. I believe those props and targets are owned by the compiler team.

That said, I do have a little experience with the FUTD so if you want me to take a look, or help out, let me know.

jjonescz commented 12 months ago

Investigated, but don't understand why FUTDC doesn't see the removed file.

When Counter2.razor is added, I see output:

Build started at 14:39...
1>FastUpToDate: Build acceleration is not enabled for this project. See https://aka.ms/vs-build-acceleration. (BlazorApp1)
1>FastUpToDate: Comparing timestamps of inputs and outputs: (BlazorApp1)
1>FastUpToDate:     Adding UpToDateCheckBuilt outputs: (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\BlazorApp1.dll (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\obj\Debug\net8.0\BlazorApp1.dll (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\obj\Debug\net8.0\BlazorApp1.pdb (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\BlazorApp1.pdb (BlazorApp1)
1>FastUpToDate:     Adding newest import input: (BlazorApp1)
1>FastUpToDate:         C:\Program Files\dotnet\sdk\8.0.100-rtm.23506.1\Sdks\Microsoft.NET.Sdk.Razor\targets\Sdk.Razor.CurrentVersion.targets (BlazorApp1)
1>FastUpToDate:     Adding Compile inputs: (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Program.cs (BlazorApp1)
1>FastUpToDate:     Adding UpToDateCheckInput inputs: (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\App.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Layout\MainLayout.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Layout\NavMenu.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Pages\Counter.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Pages\Counter2.razor (BlazorApp1)
1>FastUpToDate: Input UpToDateCheckInput item 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Pages\Counter2.razor' is newer (2023-11-02 14:38:33.211) than earliest output 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\BlazorApp1.dll' (2023-11-02 14:34:28.129), not up-to-date. (BlazorApp1)
1>FastUpToDate: Up-to-date check completed in 0.7 ms (BlazorApp1)
1>------ Build started: Project: BlazorApp1, Configuration: Debug Any CPU ------
1>C:\Program Files\dotnet\sdk\8.0.100-rtm.23506.1\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(311,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
1>BlazorApp1 -> C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\BlazorApp1.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 14:39 and took 00.612 seconds ==========

When Counter2.razor is removed, the output is:

Build started at 14:39...
1>FastUpToDate: Build acceleration is not enabled for this project. See https://aka.ms/vs-build-acceleration. (BlazorApp1)
1>FastUpToDate: Comparing timestamps of inputs and outputs: (BlazorApp1)
1>FastUpToDate:     Adding UpToDateCheckBuilt outputs: (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\BlazorApp1.dll (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\obj\Debug\net8.0\BlazorApp1.dll (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\obj\Debug\net8.0\BlazorApp1.pdb (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\BlazorApp1.pdb (BlazorApp1)
1>FastUpToDate:     Adding newest import input: (BlazorApp1)
1>FastUpToDate:         C:\Program Files\dotnet\sdk\8.0.100-rtm.23506.1\Sdks\Microsoft.NET.Sdk.Razor\targets\Sdk.Razor.CurrentVersion.targets (BlazorApp1)
1>FastUpToDate:     Adding Compile inputs: (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Program.cs (BlazorApp1)
1>FastUpToDate:     Adding UpToDateCheckInput inputs: (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\App.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Layout\MainLayout.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Layout\NavMenu.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Pages\Counter.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Pages\Error.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Pages\Home.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Pages\Weather.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Routes.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\_Imports.razor (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Layout\MainLayout.razor.css (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Layout\NavMenu.razor.css (BlazorApp1)
1>FastUpToDate:         C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\obj\Debug\net8.0\BlazorApp1.csproj.BuildWithSkipAnalyzers (BlazorApp1)
1>FastUpToDate:     No inputs are newer than earliest output 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\BlazorApp1.dll' (2023-11-02 14:39:02.736). Newest input is 'C:\Program Files\dotnet\sdk\8.0.100-rtm.23506.1\Sdks\Microsoft.NET.Sdk.Razor\targets\Sdk.Razor.CurrentVersion.targets' (2023-11-02 14:33:11.979). (BlazorApp1)
1>FastUpToDate: Checking built output (UpToDateCheckBuilt with Original property) file: (BlazorApp1)
1>FastUpToDate:     Source      2023-11-01 11:36:26.984: 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Layout\MainLayout.razor.css' (BlazorApp1)
1>FastUpToDate:     Destination 2023-11-01 11:37:17.999: 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\obj\Debug\net8.0\scopedcss\Components\Layout\MainLayout.razor.rz.scp.css' (BlazorApp1)
1>FastUpToDate: Checking built output (UpToDateCheckBuilt with Original property) file: (BlazorApp1)
1>FastUpToDate:     Source      2023-11-01 11:36:26.989: 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\Components\Layout\NavMenu.razor.css' (BlazorApp1)
1>FastUpToDate:     Destination 2023-11-01 11:37:18.000: 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\obj\Debug\net8.0\scopedcss\Components\Layout\NavMenu.razor.rz.scp.css' (BlazorApp1)
1>FastUpToDate: Checking items to copy to the output directory: (BlazorApp1)
1>FastUpToDate:     Checking copy items from project 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\BlazorApp1.csproj': (BlazorApp1)
1>FastUpToDate:         Checking PreserveNewest item (BlazorApp1)
1>FastUpToDate:             Source      2023-11-01 11:36:26.947: 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\appsettings.json' (BlazorApp1)
1>FastUpToDate:             Destination 2023-11-01 11:36:26.947: 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\appsettings.json' (BlazorApp1)
1>FastUpToDate:         Checking PreserveNewest item (BlazorApp1)
1>FastUpToDate:             Source      2023-11-01 11:43:26.620: 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\global.json' (BlazorApp1)
1>FastUpToDate:             Destination 2023-11-01 11:43:26.620: 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\global.json' (BlazorApp1)
1>FastUpToDate:         Checking PreserveNewest item (BlazorApp1)
1>FastUpToDate:             Source      2023-11-02 14:39:02.736: 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\obj\Debug\net8.0\apphost.exe' (BlazorApp1)
1>FastUpToDate:             Destination 2023-11-02 14:39:02.736: 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\BlazorApp1.exe' (BlazorApp1)
1>FastUpToDate:         Checking PreserveNewest item (BlazorApp1)
1>FastUpToDate:             Source      2023-11-01 11:36:26.945: 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\appsettings.Development.json' (BlazorApp1)
1>FastUpToDate:             Destination 2023-11-01 11:36:26.945: 'C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\appsettings.Development.json' (BlazorApp1)
1>FastUpToDate: Project is up-to-date. (BlazorApp1)
1>FastUpToDate: Up-to-date check completed in 1.6 ms (BlazorApp1)
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Build completed at 14:39 and took 00.042 seconds ==========

Counter2.razor is not there, but FUTDC doesn't care. If I contrast that with adding and removing a .cs file, I get

Build started at 14:48...
1>FastUpToDate: Build acceleration is not enabled for this project. See https://aka.ms/vs-build-acceleration. (BlazorApp1)
1>FastUpToDate: The set of project items was changed more recently (2023-11-02 14:47:46.765) than the last successful build start time (2023-11-02 14:39:50.845), not up-to-date. (BlazorApp1)
1>FastUpToDate:     Compile item added 'Class1.cs' (BlazorApp1)
1>FastUpToDate: Up-to-date check completed in 0.5 ms (BlazorApp1)
1>------ Build started: Project: BlazorApp1, Configuration: Debug Any CPU ------
1>C:\Program Files\dotnet\sdk\8.0.100-rtm.23506.1\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(311,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
1>BlazorApp1 -> C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\BlazorApp1.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 14:48 and took 00.643 seconds ==========

and then

Build started at 14:48...
1>FastUpToDate: Build acceleration is not enabled for this project. See https://aka.ms/vs-build-acceleration. (BlazorApp1)
1>FastUpToDate: The set of project items was changed more recently (2023-11-02 14:48:26.075) than the last successful build start time (2023-11-02 14:48:06.760), not up-to-date. (BlazorApp1)
1>FastUpToDate:     Compile item removed 'Class1.cs' (BlazorApp1)
1>FastUpToDate: Up-to-date check completed in 0.3 ms (BlazorApp1)
1>------ Build started: Project: BlazorApp1, Configuration: Debug Any CPU ------
1>C:\Program Files\dotnet\sdk\8.0.100-rtm.23506.1\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(311,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
1>BlazorApp1 -> C:\Users\janjones\Code\issues\razor\9329-remove-component\BlazorApp1\bin\Debug\net8.0\BlazorApp1.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 14:48 and took 00.625 seconds ==========

Binlogs from VS don't even contain UpToDateCheckInput items for Counter2.razor (nor Class1.cs), so not sure how to debug this more.

Btw, the MSBuild items that make this work are defined here:

https://github.com/dotnet/sdk/blob/053416bc097e73bf24468818e0e35bce73580984/src/RazorSdk/Targets/Sdk.Razor.CurrentVersion.targets#L364

davidwengier commented 12 months ago

@drewnoakes is Razor missing something from our FUTD items that allows the project system to track items being removed from the project?

drewnoakes commented 12 months ago

On a phone, but the fact that removing the razor file doesn't trigger the same "items changed" event for those items seems like it might be a bug on my side. We might not be including that item in the item hash. I'll transfer this to project system and investigate.

EDIT I don't have permission to transfer. Please move it over to dotnet/project-system. Thanks.

davidwengier commented 12 months ago

Transferred. Thanks for looking at it!