.NET "error NETSDK1047: Assets file does not have a target for RID" in CI
You are publishing for a runtime identifier (RID) that restore did not produce assets for. NETSDK1047 means project.assets.json has no target for the framework/RID pair, so you must restore with that RID first.
What this error means
dotnet publish fails with "error NETSDK1047: Assets file ".../project.assets.json" doesn't have a target for 'net8.0/linux-x64'. Ensure that restore has run and that you have included ... in the RuntimeIdentifiers."
error NETSDK1047: Assets file '/app/obj/project.assets.json' doesn't have a target for
'net8.0/linux-x64'. Ensure that restore has run and that you have included 'net8.0'
in the TargetFrameworks for your project. You may also need to include 'linux-x64'
in your project's RuntimeIdentifiers.Common causes
Publish for a RID that restore did not cover
A framework-dependent restore produced no RID-specific assets, but publish requests -r linux-x64, so the assets file lacks that target.
A cached restore from a prior, RID-less run
A split pipeline restored without the RID and publish reuses that obj, so the needed target is missing.
How to fix it
Restore for the runtime identifier
- Restore with the same RID you publish for, or let publish restore.
- Avoid
--no-restoreon a RID publish unless restore already included that RID. - Re-run publish.
dotnet restore -r linux-x64
dotnet publish -c Release -r linux-x64Declare RuntimeIdentifiers in the project
List the RIDs you publish so restore always generates their targets.
<PropertyGroup>
<RuntimeIdentifiers>linux-x64;win-x64</RuntimeIdentifiers>
</PropertyGroup>How to prevent it
- Restore with the same RID you publish for.
- Declare
RuntimeIdentifiersfor self-contained publishes. - Do not reuse a RID-less restore for a RID publish.