Skip to main content

Fixed: "Unable to retrieve project metadata. Ensure it's an SDK-style project." in dotnet ef

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

In a freshly cloned .NET project, dotnet ef stopped with Unable to retrieve project metadata. Ensure it's an SDK-style project. It's an SDK-style project, and the message sent me looking in the wrong place. The real clue is the line above it, NETSDK1004: Assets file … not found: nobody had run a restore in this copy yet.

What I Was Doing​

I cloned a .NET 10 solution into a new folder and restored its local tools, because the solution pins dotnet-ef in a tool manifest:

Terminal
dotnet tool restore
Output
Restore was successful.

Then I asked the EF Core tools which migrations the project has:

Terminal
dotnet ef migrations list --project src/Dewiride.Inventory.Data --startup-project src/Dewiride.Inventory.Api

What I Expected​

Build started..., Build succeeded., and a list of migrations.

What I Got​

Output
/usr/local/share/dotnet/sdk/10.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1004: Assets file '/Users/you/projects/dewiride-inventory-api/src/Dewiride.Inventory.Data/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/Users/you/projects/dewiride-inventory-api/src/Dewiride.Inventory.Data/Dewiride.Inventory.Data.csproj]
Unable to retrieve project metadata. Ensure it's an SDK-style project.

A terminal where dotnet ef migrations list fails with error NETSDK1004: Assets file project.assets.json not found, followed by Unable to retrieve project metadata. Ensure it's an SDK-style project.

What I Checked​

Whether it's an SDK-style project. The first line of the .csproj says so:

src/Dewiride.Inventory.Data/Dewiride.Inventory.Data.csproj (first line)
<Project Sdk="Microsoft.NET.Sdk">

What the first error means. Microsoft's NETSDK1004 page explains: "NuGet writes a file named project.assets.json in the obj folder, and the .NET SDK uses it to get information about packages to pass into the compiler." And the error itself gives the fix: "Run a NuGet package restore to generate this file."

Whether the file exists. It didn't, and neither did the folder. obj is listed in .gitignore, so a fresh clone never has it:

Terminal
ls src/Dewiride.Inventory.Data/obj
Output
ls: src/Dewiride.Inventory.Data/obj: No such file or directory

dotnet build would have restored by itself, which is why this rarely shows up in normal work. dotnet tool restore restores only the tools, not the projects.

Why It Happens​

Before it builds anything, dotnet ef asks MSBuild for facts about your project, such as its output path and target framework. That step needs obj/project.assets.json, which a restore creates. Without it, MSBuild stops with NETSDK1004, and the tools report that as "Unable to retrieve project metadata". Their guess about SDK-style projects is about older project files, which aren't the problem here.

The Fix​

Restore the solution first:

Terminal
dotnet restore

dotnet build works too, since it restores before it compiles.

After the Fix​

The same command:

Output (without the log lines from the database connection)
Build started...
Build succeeded.
20261103030957_CreateCatalogTables
20261103031745_AddStockMovements

The tools built the project and listed its migrations.

A terminal where dotnet restore completes, and dotnet ef migrations list then builds the project and lists its migrations.

Common Mistakes​

MistakeWhat happensDo this instead
Editing the .csproj because the message mentions SDK-styleNothing improvesRead the NETSDK1004 line first
Assuming dotnet tool restore restores everythingOnly the tools are restoredRun dotnet restore as well
Committing obj so the file is always thereMachine-specific paths end up in GitKeep obj in .gitignore
Using --no-build on a fresh cloneNothing has been built or restoredRun dotnet build once first

Troubleshooting​

SymptomLikely causeFix
NETSDK1004: Assets file … not found before the metadata messageThe project was never restoredRun dotnet restore
The same error after a restoreThe --project path points at another project, or the restore failedCheck the restore's output and the path
Could not execute because the specified command or file was not foundThe tool itself isn't restoredRun dotnet tool restore
The metadata message with no NETSDK1004 lineThe project file really can't be evaluatedRun dotnet build and read its error

FAQ​

Do I have to do this every time?​

Only once per copy of the code, and again after someone changes the packages. After that, dotnet ef builds and restores as it normally does.

Why did it work on my other machine?​

That copy had already been built, so its obj folder existed.

Conclusion​

"Unable to retrieve project metadata. Ensure it's an SDK-style project." on a fresh clone doesn't mean your project file is wrong. The line above it, NETSDK1004, says project.assets.json is missing, because obj isn't in Git and nothing has run a restore. Run dotnet restore once, and dotnet ef works.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.