.netazure-devopsmsbuildazure-pipelines.net-8.0

"project.assets.json doesn't have a target for 'net8.0-windows10.0.22621.0'", but it does, and package restore was successful?


I have two simple console applications in a solution, and I am trying to build them using an azure devops build pipeline. They will build just fine on any laptop, but the azure devops build pipeline throws the following error (relevant excerpt):

##[error]C:\Program Files\dotnet\sdk\8.0.303\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): Error NETSDK1005: 
Assets file 'F:\SomePath\MyProject\obj\project.assets.json' doesn't have a target for 'net8.0-windows10.0.22621.0'. 
Ensure that restore has run and that you have included 'net8.0-windows10.0.22621.0' in the TargetFrameworks for your project.

C:\Program Files\dotnet\sdk\8.0.303\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1005: 
Assets file 'F:\SomePath\MyProject\obj\project.assets.json' doesn't have a target for 'net8.0-windows10.0.22621.0'. 
Ensure that restore has run and that you have included 'net8.0-windows10.0.22621.0' in the TargetFrameworks for your project. [F:\SomePath\MyProject\MyProject.csproj]

I don't understand this though, the csproj files of both projects contain the following line: <TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>

I have searched online for others having this problem, and other times this error has been posted, the suggestions are to perform a nuget restore, but I am already doing this: The previous step in the pipeline was a nuget restore, which runs successfully.

I'm not sure how to even begin trying to diagnose this, everything the error is referencing appears to be as it should be.


Solution

  • According to the official documentation for NETSDK1005, the NuGet version should be higher than 5.8.

    In your screenshot, it seems that you didn't specify the version of NuGet.

    I can reproduce the issue when I created a simple Net8 console project and use the old NuGet version.

    NuGet 5.5

    When I changed to use the NuGet 5.8, it works.

    NuGet 5.8