Skip to content

[release/11.0] Fix compiled Razor views in F# MVC template - #69300

Merged
danroth27 merged 5 commits into
dotnet:release/11.0from
danroth27:fix-fsharp-mvc-compiled-views
Sep 17, 2026
Merged

danroth27 merged 5 commits into
dotnet:release/11.0from
danroth27:fix-fsharp-mvc-compiled-views

Conversation

@danroth27

@danroth27 danroth27 commented Sep 15, 2026

Copy link
Copy Markdown
Member

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:

InvalidOperationException: The view 'Index' was not found.

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?

  • Yes
  • No

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

  • High
  • Medium
  • Low

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.dll as an MVC application part.

Verification

  • Manual (required)
  • Automated

Manual validation:

  • Generated the modified F# MVC template using a custom template hive.
  • Built and published the generated .NET 11 project without warnings.
  • Verified / and /Home/Error return HTTP 200 from the built application.
  • Verified / returns HTTP 200 from the published application.

Automated validation:

  • Re-enabled build, publish, and runtime page validation in the F# MVC template integration tests.
  • The template Helix test leg is passing.
  • The remaining PR validation is still running.

Packaging changes reviewed?

  • Yes
  • No
  • N/A

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:

  • Disables the Razor source generator and enables build- and publish-time Razor compilation.
  • Adds a small F# AddCompiledRazorViews extension that loads the generated <ApplicationName>.Views.dll and registers it as a CompiledRazorAssemblyPart.
  • Re-enables build, publish, and runtime page validation for the F# MVC template tests.

The helper is isolated in MvcBuilderExtensions.fs to keep Program.fs focused on normal application startup and to avoid changing shared SDK behavior late in the release.

Validation:

  • Instantiated the modified F# MVC template with a custom template hive.
  • Built and published the generated .NET 11 project without warnings.
  • Verified / and /Home/Error return HTTP 200 from the built app.
  • Verified / 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.

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
@danroth27
danroth27 marked this pull request as ready for review September 17, 2026 18:06
Copilot AI lite review requested due to automatic review settings September 17, 2026 18:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.dll as 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
Comment thread src/ProjectTemplates/test/Templates.Mvc.Tests/MvcTemplateTest.cs
@Youssef1313 Youssef1313 added the Servicing-consider Shiproom approval is required for the issue label Sep 17, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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
@halter73 halter73 changed the title Fix compiled Razor views in F# MVC template [release/11.0] Fix compiled Razor views in F# MVC template Sep 17, 2026
@Youssef1313
Youssef1313 requested a review from artl93 September 17, 2026 21:13
@danroth27
danroth27 merged commit 6639242 into dotnet:release/11.0 Sep 17, 2026
28 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc2 milestone Sep 18, 2026
@tkapin
tkapin self-requested a review September 18, 2026 12:20
@davpetr
davpetr self-requested a review September 18, 2026 13:31
@tkapin

tkapin commented Sep 18, 2026

Copy link
Copy Markdown
Member

M2 approved for RC2

@tkapin tkapin added the Servicing-approved Shiproom has approved the issue label Sep 18, 2026
@dotnet-policy-service dotnet-policy-service Bot removed the Servicing-consider Shiproom approval is required for the issue label Sep 18, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants