14
votes

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?

3
Do you have an appropriate .tfignore/.gitignore (depending on which you're using for source control) that excludes the bin, obj, and packages folders? Can you confirm that these folders are not in source control?Daniel Mann
There is a .gitignore file in the root folder. I believe it is the default one for Visual Studio with some minro changes. Yes there are rules for the bin, obj and **/packages/* (nuget)Rui Jarimba
Did someone override the .gitignore and accidentally commit them to source control?Daniel Mann
@DanielMann you mean the nuget packages? No, packages are not under source control.Rui Jarimba
I know that nuget needs every project in the dependency graph to be restored. I believe building a solution in Visual Studio will not build or restore projects not in the solution, even if a project in the solution has a project reference to it, but I don't know if msbuild has the same limitation. I suspect yes, because Visual Studio heavily uses MSBuild under the covers. If this is the case you're running into, it's a known issue/by design. It doesn't answer why there's a change in behaviour though.zivkan

3 Answers

17
votes

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

8
votes

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

5
votes

My problem turned out to be a solution that didn't include all the necessary projects.

I have a master solution file that includes all my projects, and a number of smaller solution files with only some of the projects. The master solution built fine in Azure DevOps, but the partial solution failed.

I realized that the missing project.assets.json file belonged to a project that needed to be included in this failing solution.