Blazor is not "compiling" all of my .razor pages

Viewed 87

OP: Why can't Blazor build and find a page almost identical to another one

Blazor server-side app (3.1). I have two components, a ListX.razor and a ListY.razor. ListX is under Pages\X\Listx.razor and ListY is under Pages\Y\ListY.razor

Both start with @page directives (@page "/ListX"; @page "/ListY"). When I look in obj/Debug/netcoreapp3.1/RazorDeclaration/Pages/ListX folder, I find a ListX.razor.g.cs file. When I look in the obj/Debug/netcoreapp3.1/RazorDeclaration/Pages/ListY folder, there is nothing.

I have two NavLinks: <NavLink class="nav-link" href="listx"> and a <NavLink class="nav-link" href="listy">.

ListX displays just fine, ListY gives me "Sorry, there's nothing at this address." which is the NotFound component.

What gives?

1 Answers

After getting a little grayer and little more frustrated, I looked at the .csproj file on a whim. Lo and behold, there was a <compile remove= for the folders and files I was having trouble with. Cleaned up the .csproj file and everything now builds and runs just fine.

Moral of the story: If you are seeing something really weird, go back to basics. If that doesn't help go further back to basics.

In this case, reviewing Blazor routing and comparing the two components wasn't working. So, I went back to "what might prevent a file from being compiled or included in the build output" and voila!

Related