Search code examples
asp.net-web-apiazure-devops.net-7.0

Azure DevOps Build error NETSDK1005: Assets file doesn't have a target for net7.0


I have created new project using template ASP.NET Core Web API in Visual Studio 2022. This is simple API project and have not change anything in the template except in program.cs'; moved out swagger outside the if (app.Environment.IsDevelopment())so that I can use swagger when deploy application inAzure App Service'

app.UseSwagger();
app.UseSwaggerUI();

I am using Azure DevOps and getting build error which I need to resolve

error

##[error]C:\Program Files\dotnet\sdk\7.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): Error NETSDK1005: Assets file 'D:\a\1\s\MyApp.Web.APIs\obj\project.assets.json' doesn't have a target for 'net7.0'. Ensure that restore has run and that you have included 'net7.0' in the TargetFrameworks for your project.

enter image description here

In project.assets.json file, I can see TargetFrameworks is set to 7.0

enter image description here

not really sure, what I am missing from the puzzle.


Solution

  • According to the official documentation, the NuGet version should be higher than 5.8. We got the same error too. What we did was

    • Add a NuGet Installer task as a previous step to NuGet restore (already included if you are using the classic editor in DevOps to define the pipeline).
    • In the task, you can mention the version of NuGet, which we mentioned as 5.8

    pipeline task screenshot