Fix it fast
Most likely: obj/project.assets.json was restored for a different target framework or runtime identifier than the one used by the current build or publish command.
1. Confirm this is your error
error NETSDK1005: Assets file 'obj/project.assets.json' doesn't have a target for 'net8.0'.
error NETSDK1047: Assets file 'obj/project.assets.json' doesn't have a target for 'net8.0/win-x64'. 2. Check the cause
grep -n "<TargetFramework\|<TargetFrameworks\|<RuntimeIdentifier\|<RuntimeIdentifiers" *.csproj
dotnet restore -v minimal
dotnet build --no-restore 3. Apply the safe fix
# Restore using the same target framework and runtime identifier you build or publish with.
dotnet restore -r <rid>
dotnet publish -r <rid>
# If obj/bin are stale from a different TFM or RID, clean and regenerate build outputs.
dotnet clean
dotnet restore
dotnet build 4. Verify it works
dotnet build
dotnet publish -r <rid> Don't use unsafe shortcuts
- Do not reuse cached
obj/folders across target frameworks or runtime identifiers. - Do not run build or publish with
--no-restoreafter changingTargetFrameworksorRuntimeIdentifiers. - Do not add random RIDs, make sure the RID used by publish is listed when the project requires
RuntimeIdentifiers.
What Broke in the Dependency Graph
The existing assets file was restored for a different target framework or runtime identifier than the current build or publish command.
Repair the dependency graph
Restore for the specific TFM or RID, and include -r <rid> if publishing with a RID.
Delete obj/ and bin/ if needed, then restore and build again.
Ensure RuntimeIdentifiers includes the RID used by build or publish.
Validation
Re-run the failing command and confirm the original code/message is gone, and confirm expected artifacts or outputs exist (packages restored, build/publish succeeds).
Why Resolution Broke
Usually this comes down to stale obj/ came from a restore that targeted different TFMs, you are building or publishing with -r <rid> but restored without that RID, or CI caches or shares obj/ across TFMs or RIDs.
Prove the Graph Is Clean Again
dotnet build or dotnet publish succeeds without NETSDK1005 or NETSDK1047.
obj/project.assets.json contains a target for the requested TFM, and RID when applicable.
Mechanism
Assets file targets are keyed by TargetFramework, and sometimes by TargetFramework plus RuntimeIdentifier. If you build with a new TFM or RID but didn’t restore for it, NETSDK1005 or NETSDK1047 fires.
Keep the Dependency Graph Healthy
To prevent this, do not cache or share obj/ across different TFMs or RIDs, cache global packages instead, and always restore in the same configuration you build or publish.
Docs and source code
NETSDK1005 message template
Assets file missing a TargetFramework target. - GitHub
<data name="AssetsFileMissingTarget" xml:space="preserve">
<value>NETSDK1005: Assets file '{0}' doesn't have a target for '{1}'. Ensure that restore has run and that you have included '{2}' in the TargetFrameworks for your project.</value>
<comment>{StrBegins="NETSDK1005: "}</comment>
</data> NETSDK1047 message template
Assets file missing a TargetFramework/RuntimeIdentifier target. - GitHub
<data name="AssetsFileMissingRuntimeIdentifier" xml:space="preserve">
<value>NETSDK1047: Assets file '{0}' doesn't have a target for '{1}'. Ensure that restore has run and that you have included '{2}' in the TargetFrameworks for your project. You may also need to include '{3}' in your project's RuntimeIdentifiers.</value>
<comment>{StrBegins="NETSDK1047: "}</comment>
</data>