Skip to content

Quick Fix for the NETSDK1004 Compile Error

What Does the NETSDK1004 Message Mean?

Error NETSDK1004: "Assets file 'C:project.assets.json' not found. Run a NuGet package restore to generate this file.Code language: JavaScript (javascript)

The NETSDK1004 compile error occurred when I was refactoring the CSPROJ files within my solution. In the process, I created a Directory.Build.props file, copying out the Project root element from the CSPROJ file including the SDK.  (In my case, I happened to be moving out C# 8.0’s Nullable element – enable.)  The result was the above compile error.

The SDK XML Attribute was the Mistake

The SDK attribute causes the above error along with multiple occurrences of this associated warning:

warning MSB4011: "C:Program Filesdotnetsdk3.1.100SdksMicrosoft.NET.SdkSdkSdk.targets" cannot be imported again. It was already imported at "…Directory.Build.props". This is most likely a build authoring error. This subsequent import will be ignored.Code language: CSS (css)

Pull out the SDK attribute and the error goes away. Here’s the corrected Directory.Build.props file:

</Project>Code language: HTML, XML (xml)

Note: This example also pulls out the TargetFramework element.

If you are working with a solution and all projects are C# 8.0, I recommend you refactor out the Nullable attribute into a Directory.Build.props file as shown in this example, rather than individually edit it in all the CSPROJ files independently.

Want More?

Check out our blog How to Publish NuGets with Azure DevOps for more information on NuGet packages! Microsoft also offers documentation on the NETSDK1004 error.