[release/11.0] Fix compiled Razor views in F# MVC template - #69300
Conversation
Compile Razor views at build and publish time, then explicitly register the generated views assembly from the F# application. Re-enable build, publish, and runtime coverage for the F# MVC template. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b5857d4e-7fdc-4e51-a1fc-80cb46db6a6b
Keep Program.fs focused on application startup and follow .NET naming conventions for the AddCompiledRazorViews extension method. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b5857d4e-7fdc-4e51-a1fc-80cb46db6a6b
Use MvcBuilderExtensions.fs to match the extension type defined by the F# MVC template. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b5857d4e-7fdc-4e51-a1fc-80cb46db6a6b
There was a problem hiding this comment.
🟢 Approval recommended
The scoped changes address the reported F# MVC view-registration regression and restore integration coverage.
Pull request overview
Fixes compiled Razor view discovery for generated F# MVC applications.
Changes:
- Enables build/publish-time Razor compilation.
- Registers the generated
.Views.dllas a compiled Razor application part. - Re-enables F# template build, publish, and runtime validation.
File summaries
| File | Description |
|---|---|
StarterWeb-FSharp.fsproj.in |
Configures Razor compilation and includes the helper. |
Program.fs |
Registers compiled Razor views. |
MvcBuilderExtensions.fs |
Loads and registers the generated views assembly. |
MvcTemplateTest.cs |
Validates configuration and generated app behavior. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Include MvcBuilderExtensions.fs in the expected generated files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 11a92803-351c-4568-9f69-02f9dd236ab1
|
Hi @danroth27. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge. To learn more about how to prepare a servicing PR click here. |
Apply the established certificate-related conditions now that the F# template tests launch built and published applications. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 11a92803-351c-4568-9f69-02f9dd236ab1
|
M2 approved for RC2 |
|
Hi @danroth27. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed. |
Description
The F# MVC template generates applications that build successfully but fail at runtime because their Razor views are not compiled or registered.
This change enables build- and publish-time Razor compilation and registers the generated views assembly. The workaround is limited to generated F# MVC applications and does not change shared SDK or framework behavior.
Fixes #69220
Customer Impact
Customers creating an F# MVC application using
dotnet new mvc -lang F#with .NET 11 RC2 get an application that fails when a view is requested:Without this fix, the F# MVC template shipped in RC2 is unusable without customers manually adding Razor Runtime Compilation or implementing an equivalent workaround.
Regression?
This is a regression from .NET 11 RC1. It was introduced when Razor Runtime Compilation was removed from the F# MVC template as part of #69114.
Risk
The change is isolated to the F# MVC project template. It restores view compilation and discovery without changing shared runtime or SDK behavior, other project templates, or existing applications.
The generated project uses the existing Razor build-time compilation support and explicitly registers its generated
<ApplicationName>.Views.dllas an MVC application part.Verification
Manual validation:
/and/Home/Errorreturn HTTP 200 from the built application./returns HTTP 200 from the published application.Automated validation:
Packaging changes reviewed?
Original PR description
The F# MVC template previously relied on Razor Runtime Compilation because Razor source generation requires a C# compilation. Removing Runtime Compilation caused generated projects to build successfully but fail at runtime because their views were not compiled or registered.
This change keeps the template as a single F# project and limits the workaround to generated F# MVC applications:
AddCompiledRazorViewsextension that loads the generated<ApplicationName>.Views.dlland registers it as aCompiledRazorAssemblyPart.The helper is isolated in
MvcBuilderExtensions.fsto keepProgram.fsfocused on normal application startup and to avoid changing shared SDK behavior late in the release.Validation:
/and/Home/Errorreturn HTTP 200 from the built app./returns HTTP 200 from the published app.A full local template test build was blocked by repository prerequisites for ANCM and
blazor.web.js; CI will exercise the re-enabled F# template integration path.