How to Generate a Missing project.assets.json in Azure DevOps

We started a few weeks ago to target .Net Standard in our class libraries. While our applications remain for the foreseeable future on the .Net (Full) Framework, we like to start moving code towards .Net Core. Building our solutions in Visual Studio worked without any problems, but as soon as we try to do that in Azure DevOps, we run into this error:

C:\Program Files\dotnet\sdk\2.2.105\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(208,5): Error NETSDK1004: Assets file ‘c:\agent\_work\95\s\***\obj\project.assets.json’ not found. Run a NuGet package restore to generate this file.

We have a NuGet package restore task that fetches all the packages we need. It seems as if those project.assets.json files are only generated when we use the dotnet restore command. However, if we only use this command, we get errors because packages are missing.

It took us some time to figure out that we can combine both tasks in the same build:

Everything works when we combine the 2 restore tasks

We now do a restore using the NuGet restore task followed by a call to dotnet restore. That adds 1 minute to our build, but all the errors are gone and we can focus on moving code to .Net Standard.

Please leave a comment if you know a better approach that can replace our workaround.

5 thoughts on “How to Generate a Missing project.assets.json in Azure DevOps”

  1. Informative post. Concept has been explained very well.Looking forward for such informative posts

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.