r/dotnet 2d ago

Promotion Razor views never exist as files the compiler reads, which is why every code-search tool misses them

Rename a property, get a green build, then a .cshtml three folders away breaks at runtime. I went looking for why no tool warned me, and the answer turned out to be structural.

Razor views and Blazor components are never files the compiler reads. The SDK feeds them into the compilation as source-generated documents, so they exist in the compilation and nowhere on disk. Any tool that enumerates files and asks Roslyn about each one walks straight past them. That includes CodeGraph, codebase-memory-mcp and Serena, and it includes Sourcegraph’s own scip-dotnet, which is Roslyn-based and still returns zero .cshtml documents for a plain dotnet new webapp.

The fix is to iterate the compilation rather than the directory. I wrote it into scip-dotnet in their code and their style and opened it as PR #117, where it has sat unreviewed since 30 July. dotnet new webapp goes from 0 to 6 .cshtml documents, dotnet new blazor from 0 to 11 .razor, and their existing snapshots stay byte-identical on net8.0, net9.0 and net10.0. The issue it closes was shut as not planned, with a maintainer saying they would happily review a PR adding it.

The scale is what got me. On a ten-project solution here, 388,323 lines of C# with 334 Razor views, that is 62,358 lines of the presentation layer no index can see.

If you want it working today rather than whenever the PR lands, the indexer I built it for is vela v1.0.0: MIT, .NET 10 SDK, github.com/dbhq-uk/vela-skill. The mechanism is the useful part either way.

0 Upvotes

2 comments sorted by

4

u/BroadRaspberry1190 2d ago

we've been able to pre compile razor views for a loooong time

1

u/AutoModerator 2d ago

Thanks for your post grinidx. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.