Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assets file project.assets.json not found when running a build on Azure Devops

I have a build pipeline configured for a Service Fabric solution on Azure DevOps like this:

Build tasks

Everything was fine until a few days ago when the build started failing on a particular build agent (private), with the following error (for a few projects):

C:\Program Files\dotnet\sdk\2.1.200\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(327,5): Error : Assets file 'F:\Agent03\w\84\s\src\MyProject.Sam.Tiles.Domain\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.

The failing task is the Build solution $(PathToSolution) one.

The weird thing is that the build fails when running on some agents but with others the build is fine.

Some details:

  • Use NuGet 4.x task started using NuGet v4.9.1 very recently, I think. I tried using v4.8.1 with no luck;
  • Most of the projects use the PackageReference format, but the .sfproj project uses the packages.config file
  • I tried using the dotnet restore task but there is an error when trying to restore the packages for the .sfproj project:

    `Error : Unable to find the '....\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.7\build\Microsoft.VisualStudio.Azure.Fabric.Application.props' file. Please restore the 'Microsoft.VisualStudio.Azure.Fabric.MSBuild' Nuget package

Any idea on what might be causing this issue?

like image 685
Rui Jarimba Avatar asked Nov 29 '18 16:11

Rui Jarimba


People also ask

How does JSON generate project assets?

json file is generated in the process of restoring the NuGet packages in projects that use project. json . It holds a snapshot of all the information that is generated as NuGet walks the graph of packages and includes the version, contents, and dependencies of all the packages in your project.

How do I fix netsdk1004?

To resolve the error, remove the % from the folder name, and rerun dotnet build . A change to the project file wasn't automatically detected and restored by the project system. To resolve the error, open a command prompt and run dotnet restore on the project.

What is set up build in Azure DevOps?

The Build service in Azure DevOps Server helps you set up and manage CI for your applications. Continuous Delivery (CD) is a process by which code is built, tested, and deployed to one or more test and production environments. Deploying and testing in multiple environments increases quality.

What is the use of project assets JSON file?

The project.assets.json file maintains a project's dependency graph when using the PackageReference management format, which is used to make sure that all necessary packages are installed on the computer. Because this file is generated dynamically through package restore, it's typically not added to source control.

What to do if Visual Studio 2017 assets file is not found?

visual studio 2017 - Assets file project.assets.json not found. Run a NuGet package restore - Stack Overflow Assets file project.assets.json not found. Run a NuGet package restore

Why is my assets file not found in NuGet?

Assets file '<path>\project.assets.json' not found. Run a NuGet package restore to generate this file. The project.assets.json file maintains a project's dependency graph when using the PackageReference management format, which is used to make sure that all necessary packages are installed on the computer.

Is DotNet restore the only way to generate asset JSON files?

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.


2 Answers

Some of the projects use the PackageReference format but the .sfproj project uses the packages.config file.

I still don't understand why the build started failing, but I was able to find a workaround. Given that PackageReference is not yet supported in Service Fabric projects, my workaround was to use both restore tasks as follows:

Build tasks

like image 185
Rui Jarimba Avatar answered Oct 22 '22 09:10

Rui Jarimba


Trevor's comment on 2/20 gave me the clue. You likely don't have the complete set of projects referenced by the solution. (ProjectReferences may go to other projects, which are not in the solution).

Here is why this crazy workaround (run dotnet.exe and nuget.exe restore tasks) worked:

dotnet restore will walk project references by default to ensure they are restored also. --no-dependencies switch can turn that off.

nuget.exe restore has the opposite default, because we didn't want to break old users. -recursive can turn this on.

The right solution is to make your solution contain all the projects.

-Rob Relyea NuGet Client Team, Engineering Manager

like image 41
Rob Relyea Avatar answered Oct 22 '22 09:10

Rob Relyea