In ASP.NET Core 10, what is the difference between framework-dependent and self-contained publish output, and which one does dotnet publish produce by default?
answer
- the runtime is either installed or shipped
- Microsoft.AspNetCore.App shared framework
- rolls forward to the latest patch
- SelfContained MSBuild property
- a RID no longer implies self-contained
basics
~20 sFramework-dependent output, the default, holds only the app and its dependencies and runs on an installed .NET and ASP.NET Core runtime that it rolls forward to the latest patch. Self-contained output also ships the runtime: bigger, platform-specific, patched only by republishing.
solid answer
~40 sA **framework-dependent** publish, the default, writes your assembly, its NuGet dependencies, `*.deps.json`, `*.runtimeconfig.json` and an apphost executable. It needs the .NET runtime and the `Microsoft.AspNetCore.App` shared framework on the machine, and it **rolls forward to the latest installed patch**, so the host's runtime updates patch the app. A **self-contained** publish (`<SelfContained>true</SelfContained>` with a runtime identifier) copies the runtime and ASP.NET Core into the output: no install needed and you control the exact version, but the output is much larger, is built per platform, and only gets a runtime security fix when **you republish**. Since .NET 8, specifying a runtime identifier no longer implies self-contained; `PublishAot`, `PublishTrimmed` and `PublishSingleFile` do imply it at publish. In containers the choice maps to the base image: `dotnet/aspnet` for framework-dependent, `dotnet/runtime-deps` for self-contained.
code
xml · 6 lines<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<!-- opt in: ship the runtime with the quiz-game API -->
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
</PropertyGroup>go deeper
Recall that framework-dependent is the default and needs .NET installed, while self-contained ships the runtime and is larger.
Explain roll-forward to the latest patch, which files each output contains, and the .NET 8 change to RuntimeIdentifier defaults.
Choose per deployment target and make runtime patching part of the release process, especially for self-contained or AOT output.
Set a fleet-wide policy for runtime patching and base images that balances version pinning against security update speed.
## Two ways to ship the same app `dotnet publish` produces the files you deploy. The central decision is **who provides the .NET runtime**: the machine the app lands on, or the app itself. ### Framework-dependent (the default) The output contains: - your app's assembly (for a project called `QuizGame.Api`, `QuizGame.Api.dll`) and the NuGet packages it uses; - `QuizGame.Api.deps.json`, which lists dependencies, and `QuizGame.Api.runtimeconfig.json`, which names the frameworks to load: `Microsoft.NETCore.App` and, for a web project, `Microsoft.AspNetCore.App`; - an **apphost** executable (`QuizGame.Api` on Linux, `QuizGame.Api.exe` on Windows), because `UseAppHost` defaults to `true`; `dotnet QuizGame.Api.dll` also works. The machine must have a compatible .NET runtime and the ASP.NET Core shared framework installed. At start-up the host binds to the **latest installed patch** of the targeted major and minor version, so installing a security update on the server patches every framework-dependent app on it without republishing. ### Self-contained With `<SelfContained>true</SelfContained>` and a runtime identifier such as `linux-x64`, the output also contains the .NET runtime and the ASP.NET Core libraries. The .NET docs list the trade-offs: | | Framework-dependent | Self-contained | |---|---|---| | Runtime on target | Must be installed | Shipped with the app | | Output size | Small | Much larger | | Platform | IL portable; apphost per platform | One build per runtime identifier | | Runtime security patches | Picked up by rolling forward | Only by **republishing** | | Version control | The host decides the patch | You pin the exact version | Self-contained output still needs the operating system's native dependencies (the C runtime, OpenSSL, ICU unless running invariant). Trimming and invariant globalization can shrink it. ## What changed in .NET 8 Before .NET 8, setting a `RuntimeIdentifier` made an app self-contained by default. For apps targeting .NET 8 or later, a runtime identifier **no longer implies `SelfContained`**: you get a framework-dependent, platform-specific build unless you ask for self-contained. At `dotnet publish`, `PublishAot`, `PublishTrimmed` and `PublishSingleFile` still imply self-contained unless `PublishSelfContained` is set to `false`, because those modes need the runtime inside the output. `PublishReadyToRun` no longer implies it. ## How the choice shows up in containers The SDK's container support picks the base image from the same decision: - framework-dependent ASP.NET Core app: `mcr.microsoft.com/dotnet/aspnet`, which already contains the runtime and shared framework; the entry point is `dotnet /app/QuizGame.Api.dll`; - self-contained (including Native AOT): `mcr.microsoft.com/dotnet/runtime-deps`, which holds only native dependencies; the entry point is the app's own executable. For the **quiz-game API**, framework-dependent on the `aspnet` image is the usual choice: the image layers with the runtime are shared and patched by pulling a newer base image, and the app layer stays small. Self-contained pays off when the target cannot have .NET installed, when you must pin an exact runtime build, or when Native AOT or trimming is involved. ## Mistakes that show up in review - **Expecting a RID to bundle the runtime.** Since .NET 8 it does not; a server without .NET then fails to start the app with a missing-framework error. - **Shipping self-contained apps and forgetting them.** They never pick up runtime patches on their own, so an unmaintained one keeps a vulnerable runtime for years. - **Mixing build and publish modes.** Building framework-dependent and then publishing self-contained with `--no-build` produces inconsistent output; the docs warn to use the same options for both. - **Copying a framework-dependent build onto the `runtime-deps` image.** That image has no .NET runtime, so the app cannot start. ## Choosing in practice 1. Default to framework-dependent for servers and containers you control. 2. Choose self-contained for machines you do not control, or when trimming or Native AOT is the goal. 3. Whichever you choose, put runtime patching in the release process: for self-contained output that means rebuilding and redeploying on every .NET security release.
- How does a framework-dependent app get a .NET security fix?By default it rolls forward to the latest installed patch of its major.minor runtime, so installing the patched runtime on the host, or rebuilding the container on a newer `aspnet` base image, applies the fix without recompiling the app. A self-contained app carries its own runtime and only gets the fix when you republish it.
- Does setting RuntimeIdentifier make an ASP.NET Core 10 app self-contained?No. Since .NET 8 a runtime identifier produces a platform-specific, framework-dependent build. You get self-contained output by setting `SelfContained` to `true`, or implicitly at publish when `PublishAot`, `PublishTrimmed` or `PublishSingleFile` is set and `PublishSelfContained` is not `false`.
- Self-contained apps receive .NET security patches when the host's runtime is updated.
- Setting a RuntimeIdentifier is enough to make a .NET 10 app self-contained.
- Framework-dependent output only runs through the dotnet command, never as an executable.
- Self-contained output needs no native libraries from the operating system at all.
- Framework-dependent apps are pinned to the exact runtime patch they were built against.
Assumes .NET 10 SDK; since .NET 8 a RuntimeIdentifier no longer implies SelfContained, so a RID-specific publish is framework-dependent unless self-contained is requested.