# ASP.NET Core "dotnet publish" self-contained / runtime identifier failure in CI

> Fix "dotnet publish" failures for self-contained or runtime-specific ASP.NET Core apps in CI - a missing or wrong runtime identifier (RID) or PublishSingleFile misconfiguration.

Source: https://latchkey.dev/learn/dotnet/aspnet-dotnet-publish-self-contained-runtime-in-ci  
Updated: 2026-06-30

A self-contained or runtime-specific publish needs a runtime identifier (RID) that matches the deploy target and packages that support it. In CI it fails when the RID is missing, wrong for the runner, or a self-contained option conflicts with the project.

## Diagnose it: SDK version and restore first

Most .NET CI failures are an SDK mismatch or a restore that did not happen. `global.json` pins the SDK, and if the runner does not have that exact version the failure message is about the project rather than the SDK.

```Terminal
dotnet --info
cat global.json 2>/dev/null

# restore explicitly so a restore failure is not reported as a build failure
dotnet restore --verbosity normal
dotnet build --no-restore -warnaserror
```

> Pin the SDK with `global.json` and install exactly that version with `actions/setup-dotnet`. A floating SDK turns a runner image update into a build break on unchanged code.

## FAQ

### What causes ASP.NET core "dotnet publish" self-contained / runtime identifier failure in CI?

There are 2 common causes: the rid was not restored and a self-contained option conflicts with the project. Publishing for linux-x64 requires a restore that includes that RID; a plain restore has no target for it, so publish fails.

### How do I fix ASP.NET core "dotnet publish" self-contained / runtime identifier failure in CI?

There are 2 fixes depending on which cause you have: publish with the correct rid and restore the rid first if needed. Work through them in order, since the first is the most common.

### What does ASP.NET core "dotnet publish" self-contained / runtime identifier failure in CI actually mean?

A dotnet publish step errors with "You must specify a target framework" plus a RID prompt, "NETSDK1047: Assets file ...

### How do I stop ASP.NET core "dotnet publish" self-contained / runtime identifier failure in CI happening again?

Publish with an explicit RID that matches the deploy target. The prevention section lists 3 changes that keep it from recurring.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
