Add migration guidance for existing F# MVC applications upgrading from .NET 10 to .NET 11.
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
Description
F# MVC projects generated by earlier templates use the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package and call .AddRazorRuntimeCompilation(). Razor Runtime Compilation is obsolete in .NET 11. Unlike C# MVC projects, F# projects can't use the Razor source generator directly, so removing Runtime Compilation without additional changes causes the application to build successfully but fail when a view is requested:
InvalidOperationException: The view 'Index' was not found.
The .NET 11 F# MVC template now uses build- and publish-time Razor compilation and explicitly registers the generated <ApplicationName>.Views.dll assembly. Existing F# MVC applications that want to remove Razor Runtime Compilation should adopt the same setup.
Related product work:
- Regression: dotnet/aspnetcore#69220
- Runtime Compilation removal: dotnet/aspnetcore#69114
- F# MVC template fix: dotnet/aspnetcore#69300
Proposed guidance
Clarify that newly generated .NET 11 F# MVC projects already contain this configuration. The following steps are for existing projects migrating from an earlier version of .NET.
-
Remove the
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilationpackage reference. -
Remove the call to
.AddRazorRuntimeCompilation(). -
Configure Razor compilation in the project file:
<PropertyGroup> <UseRazorSourceGenerator>false</UseRazorSourceGenerator> <RazorCompileOnBuild>true</RazorCompileOnBuild> <RazorCompileOnPublish>true</RazorCompileOnPublish> </PropertyGroup> -
Add MvcBuilderExtensions.fs to the project before Program.fs because F# compilation order is significant:
<ItemGroup>
<!-- Other F# source files -->
<Compile Include="MvcBuilderExtensions.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
- Add MvcBuilderExtensions.fs. Its namespace must match the application's root namespace:
open System open System.IO open System.Reflection open System.Runtime.CompilerServices open System.Runtime.Loader open Microsoft.AspNetCore.Mvc.ApplicationParts open Microsoft.Extensions.DependencyInjection
[<Extension>] type MvcBuilderExtensions =
[<Extension>]
static member AddCompiledRazorViews(builder: IMvcBuilder) =
let applicationAssembly = Assembly.GetExecutingAssembly()
let viewsAssemblyName = $"{applicationAssembly.GetName().Name}.Views"
let viewsAssemblyPath =
Path.Combine(AppContext.BaseDirectory, $"{viewsAssemblyName}.dll")
let loadContext =
AssemblyLoadContext.GetLoadContext(applicationAssembly)
let viewsAssembly =
if File.Exists(viewsAssemblyPath) then
loadContext.LoadFromAssemblyPath(viewsAssemblyPath)
else
loadContext.LoadFromAssemblyName(AssemblyName(viewsAssemblyName))
builder.PartManager.ApplicationParts.Add(
CompiledRazorAssemblyPart(viewsAssembly))
builder
- Register the compiled views in Program.fs:
.AddControllersWithViews()
.AddCompiledRazorViews()
Explain that this configuration compiles Razor views during build and publish and registers the resulting views assembly with MVC. It avoids the obsolete Runtime Compilation dependency while allowing views to be discovered at runtime.
Page URL
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/migration/100-to-110.md
Document ID
3c76ffcd-7b47-b9b9-68a0-b25e375dabe9
Platform Id
542d0049-d2cb-7cae-1b4b-0d79ae30efaf
Article author
@wadepickett
Metadata
- ID: 3c76ffcd-7b47-b9b9-68a0-b25e375dabe9
- PlatformId: 542d0049-d2cb-7cae-1b4b-0d79ae30efaf
- Service: aspnet-core
- Sub-service: migration
- 主要言語
- C#
- スター
- 13.1k
- フォーク
- 24.5k
- 平均マージ
- 3日 6時間
- マージ済み PR(30日)
- 210
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dotnet/AspNetCore.Docs のほかの issue
-
aspnet-core/svc doc-enhancement mvc/subsvc Pri2
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
dotnet/AspNetCore.Docs#38016 ·
メンテナーはふだん 1 日以内に返信
-
aspnet-core/svc doc-enhancement hosting-deployment/subsvc Pri2 Source - Docs.ms
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
dotnet/AspNetCore.Docs#38009 ·
メンテナーはふだん 1 日以内に返信
-
:watch: Not Triaged CAC
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
dotnet/AspNetCore.Docs#38000 ·
メンテナーはふだん 1 日以内に返信
-
:watch: Not Triaged CAC
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
dotnet/AspNetCore.Docs#37998 ·
メンテナーはふだん 1 日以内に返信
-
[AI-Suggested] Content update request from UUF signal: Build a Blazor movie database app (Part 1 - Create a Blazor Web App) | Microsoft Learn対応中かも @guardrex が 4 日前に担当しました。 オープン:watch: Not Triaged CAC
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dotnet/AspNetCore.Docs#37995 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
dotnet/AspNetCore.Docs の issue をすべて見る
似ている issue
-
bug effort:S P3
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
nightscout/nocturne#3093 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
メンテナーはふだん 3 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100