/errors/dotnet-cli/netsdk1004-assets-file-not-found
error NETSDK1004: Assets file 'project.assets.json' not found. Run a NuGet package restore
- tool
- .NET CLI
- exit code
- 1
- versions
- .NET 6 – 10 SDK
- os
- any
error NETSDK1004: Assets file '.../obj/project.assets.json' not found. Run a NuGet package restore to generate this file. means the build started before NuGet restore had produced obj/project.assets.json, the file that lists the packages and frameworks the build should use. It usually comes from dotnet build --no-restore in a folder where dotnet restore never ran. Run dotnet restore first, or remove --no-restore.
Reproduce it
cat > App.csproj <<'EOF'
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Library</OutputType>
</PropertyGroup>
</Project>
EOF
dotnet build --no-restore -nologo 2>&1 | grep -o "error NETSDK1004: .*generate this file." | head -n 1
exit "${PIPESTATUS[0]}"Output · exit 1
error NETSDK1004: Assets file '/tmp/work/obj/project.assets.json' not found. Run a NuGet package restore to generate this file.
The full line starts with the path of the SDK targets file that raised the error and ends with the project path in brackets.
Fix
cat > App.csproj <<'EOF'
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Library</OutputType>
</PropertyGroup>
</Project>
EOF
dotnet restore -v q > /dev/null && ls obj/project.assets.json
dotnet build --no-restore -v q -nologo 2>&1 | grep -E "error|Build succeeded" | sed -E 's/ in [0-9.]+s$//'Output
obj/project.assets.json Build succeeded.
In CI pipelines
- run: dotnet restore MySolution.sln
- run: dotnet build MySolution.sln --no-restore -c Release
- run: dotnet test MySolution.sln --no-build -c ReleaseRestore and build must target the same solution or project. If you build for a runtime (-r linux-x64), restore with the same -r, otherwise the assets file lacks that runtime and you get the related error NETSDK1047: Assets file ... doesn't have a target for 'net10.0/linux-x64'.