ASP.NET Core Razor Page files in VS2022 not added correctly in .elements project file

Elements 11.0.0.2745
Visual Studio 2022 (Version 17.1.1)

There is a problem with the way Razor Page files are added to ASP.NET Core Mercury projects when using Visual Studio 2022. (I don’t know about VS2019.)

If I create a Mercury project using the ASP.NET Core Empty Web Application project template in VS2022, and then use Add New Item to add a ASP.NET Core Page Model file from the Elements => Mercury Items => ASP.NET Core templates, the file itself is fine. BUT it adds the file to the *.elements project file as a <Content> node instead of a <Razor> node. It also adds the <DependentUpon> node inside the node for the file which I don’t think is needed. Here’s a comparison of the *.elements file between Water on the left and VS2022 on the right:

This matters because the <Content> reference means that any anchor tag helper for this page doesn’t end up with the right href, so the navigation doesn’t work properly.

I added this to the _Layout.cshtml:
<a class="nav-link text-dark" asp-area="" asp-page="/About">About</a>

As a <Razor> element, href is “/About”.

But as a <Content> element, href is empty.

Unloading the project and manually editing the project file solves the problem for me.

As an aside…I assume you can’t do anything about this, but it would be great if Add => Razor Page… menu from a right click on Pages in the Solution explorer would allow me to create this kind of file, rather than needing to use the New Item… option and finding the template. Right now, choosing that option gives me an error “There are no scaffolders supported for this item.”

Thanks,

–Avonelle

Logged as bugs://E25954.

bugs://E25954 was closed as fixed.

1 Like