error NETSDK1005: Assets file '...\obj\project.assets.json' doesn't have a target for 'net10.0'.
The project's target framework changed, but the file that restore wrote still describes
the old one. Run dotnet restore (or build without
--no-restore) and the error goes away.
Here the trigger was a build with --no-restore after
TargetFramework was edited. Make sure a restore runs after every change
to the target frameworks.
The error
C:\Program Files\dotnet\sdk\10.0.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1005: Assets file '...\AssetLab\obj\project.assets.json' doesn't have a target for 'net10.0'. Ensure that restore has run and that you have included 'net10.0' in the TargetFrameworks for your project. [...\AssetLab\AssetLab.csproj]
Build FAILED.
The project paths are shortened; nothing else in the output was changed.
Why it happens
dotnet restore resolves the packages for each target framework of the
project and writes the result to obj\project.assets.json, one section per
framework. The build reads that file and does not rewrite it. When the project now asks
for net10.0 and the file only has a net9.0 section, the build
has no package graph for the framework it is compiling and stops with NETSDK1005.
A normal dotnet build runs restore first, so it never sees a stale file.
--no-restore skips that step on purpose, to save time when restore already
ran. That is safe only if nothing that restore depends on changed in between, and the
target framework is exactly such a thing: the file on disk still looked valid, it just
described a different framework.
The fix
dotnet restore
dotnet build --no-restore
Restore rewrote the assets file with a net10.0 section and the
--no-restore build then succeeded with 0 warnings. In a pipeline, keep the
restore step and the build step reading the same project files, and run restore again
after any step that edits them. When you only work in a terminal, drop
--no-restore and let dotnet build restore for you; after
switching the project back to net9.0, a plain dotnet build
restored and built without any manual step.
If the message names a framework you did not mean to build, check
TargetFramework and TargetFrameworks in the
.csproj and any Directory.Build.props above it, and a
-f option on the command line.
How it was reproduced
A console project created with dotnet new console -f net9.0 on .NET SDK
10.0.403 and built once, so obj\project.assets.json held a net9.0 target.
Then TargetFramework was edited to net10.0 and the project
built with dotnet build --no-restore, which failed as shown.
Frequently asked
- What does NETSDK1005 assets file doesn't have a target mean?
- The obj/project.assets.json file was written by a restore for other target frameworks. The project now targets a framework the file has no section for, so the build cannot find its packages.
- How do I fix NETSDK1005 after changing the target framework?
- Run dotnet restore, then build again. If your script uses dotnet build --no-restore, make sure restore runs after every change to TargetFramework or TargetFrameworks.
- Why does dotnet build --no-restore fail when dotnet build works?
- dotnet build runs restore first and refreshes project.assets.json. With --no-restore the build trusts the existing file, which is stale if the project files changed since the last restore.
More decoded errors in the Fixes category. If the assets file is missing altogether, see NETSDK1004: Assets file not found.