

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
12345# Razor Tooling and Compiler Instructions for AI Coding Agents67Razor was merged into the Roslyn repo from `dotnet/razor`, and most files keep8their original sub-tree layout9(`src/Razor/src/Razor/...`, `src/Razor/src/Compiler/...`, `src/Razor/src/Shared/...`,10`src/Razor/src/Analyzers/...`).1112## Critical Rules1314- **Bug fixes**: Look for existing code that already handles the scenario before adding new code.15 The bug is more likely in existing logic than a missing feature.16- **Helpers**: Review existing helpers (`UsingDirectiveHelper`, `AddUsingsHelper`, etc.)17 before writing new utility methods. Don't duplicate.18- **Warning levels**: Track warnings with non-zero `RazorWarningLevel` values in19 [`docs/razor/warning-levels.md`](../../docs/razor/warning-levels.md), including the diagnostic20 ID, warning level, exact message, and trigger condition.2122## File Types2324- `.razor` -- Blazor components.25- `.cshtml` -- Razor views/pages (referred to as "Legacy" in the codebase).2627## Code Patterns2829- **Collections**: Use `ListPool<T>.GetPooledObject(out var list)` and `PooledArrayBuilder<T>`30 instead of allocating new collections. Prefer immutable collection types.31- **Positions**: Use `GetRequiredAbsoluteIndex` for converting positions to absolute indexes.32- **LSP conversions**: `sourceText.GetTextChange(textEdit)` converts LSP `TextEdit` to33 Roslyn `TextChange`. Reverse: `sourceText.GetTextEdit(change)`. Both live in34 `src\Razor\src\Razor\src\Microsoft.CodeAnalysis.Razor.Workspaces\Extensions\LspExtensions_SourceText.cs`.35- **RazorCodeDocument**: Immutable -- every `With*` method creates a new instance passing ALL36 fields through the constructor. When adding a new field, thread it through every existing37 `With*` method. Prefer computing derived data via extension methods (e.g.,38 `GetUnusedDirectives()`) rather than storing computed results as fields.39- **Razor documents in Roslyn**: Stored as additional documents. Resolve via40 `solution.GetDocumentIdsWithFilePath(filePath)` then `solution.GetAdditionalDocument(documentId)`.41- **Remote services**: Place the public stub method (calling `RunServiceAsync`) directly42 above its private implementation method.43- **Visual Studio options**: Register Razor Advanced settings in44 `Microsoft.VisualStudio.RazorExtension\UnifiedSettings\razor.registration.json`, localize45 their UI text in `VSPackage.resx`, read them through `OptionsStorage`, and add remotely consumed46 values to `ClientAdvancedSettings` so `IClientSettingsManager` synchronizes changes live.4748## Adding OOP Remote Services4950When adding a new `IRemote*Service` and `Remote*Service`:51521. Interface: `src\Razor\src\Razor\src\Microsoft.CodeAnalysis.Razor.Workspaces\Remote\`532. Implementation: `src\Razor\src\Razor\src\Microsoft.CodeAnalysis.Remote.Razor\`543. Register in55 `src\Razor\src\Razor\src\Microsoft.CodeAnalysis.Razor.Workspaces\Remote\RazorServices.cs`56 (add to `MessagePackServices` or `JsonServices`).574. **Add an entry to `eng\targets\RazorServices.props`** (at the Roslyn repo root, not under58 `src\Razor`):59 `Include="Microsoft.VisualStudio.Razor.{ShortName}"` with60 `ClassName="{FullTypeName}+Factory"`. The `ShortName` is your interface name with61 `IRemote` and `Service` stripped (e.g., `IRemoteFrobulatorService` becomes `Frobulator`).625. Validate: `dotnet test src\Razor\src\Razor\test\Microsoft.CodeAnalysis.Remote.Razor.UnitTests --filter "FullyQualifiedName~RazorServicesTest"`63
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| dotnet/roslynAGENTS.md · 21k | AGENTS.md | buildagent-behaviour | 43/100 | 14 days ago | |
| dotnet/roslyn.github/instructions/Compiler.instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 99/100 | today | |
| dotnet/roslyn.github/instructions/IDE.instructions.md · 21k | Copilot instructions | stylearch | 70/100 | 14 days ago | |
| dotnet/roslyneng/common/AGENTS.md · 21k | AGENTS.md | no sections | 4/100 | 7 days ago | |
| dotnet/roslyn.github/copilot-instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 89/100 | 8 days ago |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| chihebnabil/lovable-boilerplate.github/instructions/global.instructions.md · 65 | Copilot instructions | buildlint-formatstylearch+4 | 100/100 | 14 days ago | |
| louislam/uptime-kuma.github/copilot-instructions.md · 90k | Copilot instructions | setupbuildtestlint-format+9 | 100/100 | 14 days ago | |
| pytorch/pytorch.github/copilot-instructions.md · 102k | Copilot instructions | setupbuildteststyle+5 | 100/100 | 14 days ago | |
| dotnet/roslyn.github/instructions/Compiler.instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 99/100 | today | |
| bagisto/bagisto.github/copilot-instructions.md · 28k | Copilot instructions | setupbuildteststyle+5 | 97/100 | 14 days ago | |
| hiyouga/LlamaFactory.github/copilot-instructions.md · 74k | Copilot instructions | setupbuildtestlint-format+5 | 97/100 | 13 days ago | |
| rtk-ai/rtk.github/copilot-instructions.md · 76k | Copilot instructions | buildtestlint-formatstyle+2 | 97/100 | 14 days ago | |
| JCodesMore/ai-website-cloner-template.github/copilot-instructions.md · 32k | Copilot instructions | buildlint-formatstylearch+3 | 97/100 | 7 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/dotnet-roslyn-github-instructions-razor-instructions)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.