Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

NETSDK1004: Assets file project.assets.json not found

MSBuild is missing the NuGet dependency graph. The build skipped restore, obj was deleted or moved, or two projects share one intermediate path.

~5 min readC#
#.NET#NuGet#MSBuild#Build Errors
A .NET project crate missing its assets file, a cyan NuGet restore gate and an amber obj folder plate

Introduction & Quick Summary

text
error NETSDK1004: Assets file 'D:\src\Billing\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.

The build asked MSBuild for the dependency graph it uses to resolve references, and the file that holds that graph is missing. project.assets.json is generated by NuGet restore into the obj directory; it is not produced by the compiler and is not committed to source control.

The five reasons it goes missing:

  • Restore was skipped. dotnet build --no-restore or dotnet publish --no-restore on a clean checkout.
  • obj was deleted or never restored. Cleaning with rm -rf or a CI cache that only keeps bin.
  • The path was relocated. BaseIntermediateOutputPath or MSBuildProjectExtensionsPath sends the file somewhere the build does not look.
  • Two projects share one obj. Custom intermediate paths collide and one project's restore overwrites the other's.
  • Restore failed but the build continued. Failed feeds, credentials, or a missing TFM leave no assets file and a warning that scrolls past.
Message detailMeaningFix
Path ends in obj/project.assets.jsonDefault intermediate outputRun restore
Path is outside the projectCustom intermediate pathFix BaseIntermediateOutputPath
Same path for two projectsShared intermediatesGive each project its own
Run a NuGet package restoreNo assets at alldotnet restore
Appears only with --no-restoreFlag removed implicit restoreDrop the flag

Core Mechanics, Signatures & Reproducible Setup

Restore reads the project file, resolves PackageReference items against configured feeds, writes project.assets.json plus project.nuget.cache and *.nuget.g.props into the intermediate output directory. dotnet build runs an implicit restore unless --no-restore is passed; msbuild does not restore by default for SDK-style projects invoked directly, which is why IDE builds and command-line builds diverge.

Reproduce it deterministically:

bash
dotnet new classlib -n AssetsDemo -o /tmp/assets-demo cd /tmp/assets-demo dotnet build --no-restore # error NETSDK1004: Assets file '.../obj/project.assets.json' not found.

Then restore and build:

bash
dotnet restore ls obj/ # AssetsDemo.csproj.nuget.dgspec.json project.assets.json project.nuget.cache dotnet build --no-restore

Inspect what the assets file claims, which is the fastest way to catch a wrong target framework:

bash
python3 -c " import json d=json.load(open('obj/project.assets.json')) print(d['targets'].keys()) print(d['project']['frameworks'].keys()) "

If the printed target differs from the project's TargetFramework, restore evaluated a different configuration than the build.

A typical project file that restores reliably in CI:

xml
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net9.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> </PropertyGroup> </Project>

With a lock file, CI can restore in locked mode and fail fast when the graph changed:

bash
dotnet restore --locked-mode

Key Comparison Table

CommandRestoresWrites assetsUse in CI
dotnet restoreYesYesFirst step
dotnet buildYes, implicitYesNormal build
dotnet build --no-restoreNoNoAfter an explicit restore
dotnet publishYes, implicitYesNormal publish
dotnet publish --no-restoreNoNoAfter publish-time restore
dotnet test --no-restoreNoNoAfter restore
msbuild /t:BuildNoNoRequires /t:Restore first
CauseDetectionDurable fix
Missing restoreobj has no assets fileRemove --no-restore
CI cache misses objCache key only covers binCache ~/.nuget/packages and restore
Custom intermediate pathAssets file in unusual directorySet per-project path
Shared objTwo projects, one assets fileUnique BaseIntermediateOutputPath
Failed restoreWarning above the errorFix feed credentials
Wrong SDKglobal.json pins old SDKAlign SDK and TFM

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

Case 1: A fresh clone built with --no-restore

bash
git clone https://example.com/billing.git && cd billing dotnet build --no-restore # error NETSDK1004

The flag exists to save time in a pipeline that already restored. On a fresh machine it guarantees failure. Drop the flag, or add an explicit restore step before the build:

bash
dotnet restore dotnet build --no-restore

If the reason for --no-restore was a slow feed, cache the NuGet package folder instead of skipping restore entirely.

Case 2: CI cache that restores bin but not obj

- uses: actions/cache@v4 with: path: | ~/.nuget/packages src/**/obj key: nuget-${{ hashFiles('**/*.csproj', '**/packages.lock.json') }}

Caching obj is an optimization, not a requirement; caching only bin produces binaries with no dependency graph and the next build fails. The safe minimum is the global packages folder plus a real restore step:

- run: dotnet restore --locked-mode - run: dotnet build --no-restore -c Release

Case 3: Custom BaseIntermediateOutputPath collisions

xml
<!-- Directory.Build.props --> <PropertyGroup> <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)obj\</BaseIntermediateOutputPath> </PropertyGroup>

Every project under that directory now writes to the same obj, so restore for project B overwrites A's assets file. Make the path project-specific:

xml
<PropertyGroup> <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath> </PropertyGroup>

BaseIntermediateOutputPath must be set before the SDK props are imported to take effect; a value placed after <Project Sdk="..."> is often ignored, which makes the build look at the default path while the file lands elsewhere.

Case 4: Multi-targeting where restore evaluated one framework

xml
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
bash
dotnet build -f net9.0 --no-restore # NETSDK1004 if restore only ran for net8.0

Restore evaluates all target frameworks listed at restore time; a property that changes the list conditionally per configuration breaks that:

xml
<TargetFrameworks Condition="'$(Configuration)' == 'Release'">net9.0</TargetFrameworks>

Remove the condition, or restore explicitly for the configuration you build:

bash
dotnet restore -p:Configuration=Release dotnet build -c Release --no-restore

Case 5: Restore "succeeded" while a feed was unreachable

text
warning NU1801: Unable to load the service index for source https://pkgs.example.com/v3/index.json error NETSDK1004: Assets file ... not found.

The warning explains the real failure. RestoreIgnoreFailedSources=true downgrades feed errors to warnings, so a pipeline reports a successful restore step and then fails at build with no assets. Remove the property in CI, or add a health check for the feed before restore:

curl -fsS -o /dev/null -w '%{http_code}\n' https://pkgs.example.com/v3/index.json

Private feeds also need credentials in NuGet.config or a token environment variable; an unauthenticated 401 produces the same warning-then-NETSDK1004 pattern.

Case 6: Docker builds that copy the project but not the restore output

dockerfile
COPY . . RUN dotnet publish src/Api/Api.csproj -c Release --no-restore -o /app

The image never ran restore, so the obj copied from the host may be stale or absent depending on .dockerignore. Restore inside the image with the project files first, then copy the rest:

dockerfile
COPY src/Api/Api.csproj src/Api/ RUN dotnet restore src/Api/Api.csproj COPY . . RUN dotnet publish src/Api/Api.csproj -c Release --no-restore -o /app

If .dockerignore excludes obj, the second stage has nothing to reuse and the flag must go, at the cost of restoring twice.

Common Compilation/Runtime Mistakes & Version Gotchas

  • --no-restore copied into every command. It is valid only after a matching restore with the same configuration, target framework and properties. Any difference produces a missing or stale assets file.
  • project.assets.json committed to git. It contains absolute paths in some fields and is machine-specific; committing it hides missing restores on the author's machine and breaks on CI.
  • SDK pinning through global.json. A rollForward of latestPatch keeps a project on an old SDK while the TFM targets a newer one, and restore writes assets for a framework the build cannot compile.
  • obj deleted while the IDE is open. Visual Studio keeps an in-memory project system and reports NETSDK1004 until the project is reloaded, even after a successful command-line restore.
  • .NET 10 SDK default artifacts path. Newer SDKs can place obj under an artifacts directory when UseArtifactsOutput is enabled; scripts that look for bin/obj in the project folder then miss the assets file entirely.
  • NuGet fallback folders. RestoreAdditionalProjectFallbackFolders can mask a missing package on one machine and fail on another where the folder does not exist, with NETSDK1004 as the visible symptom.

When comparing a working and a failing project file, paste both into the diff tool. The generated assets graph is JSON, so the JSON formatter makes target framework and package identity mismatches readable without scrolling a minified file.

Primary references: NETSDK1004 documents this error and the restore step that resolves it, and dotnet restore covers the options that control when assets are generated.

Official references

primary documentation

The C# documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit C# work — they run entirely in this browser tab, so nothing you paste leaves your device.

All C# guides

More in C#

All C# guides

The guides filed next to this one in C#, in library order.