Assets file project.assets.json doesn't have a target for 'net6.0' - VS2022

Viewed 11283

Just a few days ago got this error, after updating to Visual Studio Community 2022 v17.2 (from v17.1.6):

Error NETSDK1005 Assets file 'C:.........XXXXXX.Web\obj\project.assets.json' doesn't have a target for 'net6.0'. Ensure that restore has run and that you have included 'net6.0' in the TargetFrameworks for your project. XXXXXX.Web C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets 267

  • Uninstalled everything related with VS2022 + Installer
  • Rebooted
  • Fresh Git Cloned the project I'm working on (I work on several computers all with Win 10 and all with the latest updates, this is the only VS installation that presents this problem)
  • Reinstalled VS 2022 v17.2 (with .NET 6.0, the usual install)

The .csproj file has everything in place:

<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
    <IsPackable>false</IsPackable>
    <SpaRoot>ClientApp\</SpaRoot>
    <DefaultItemExcludes>$(DefaultItemExcludes);(SpaRoot)\**\node_modules\**;</DefaultItemExcludes>
    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>

Always delete the 'bin' and 'obj' folders before build or rebuild....

Cannot get away with the compilation, and always receiving that NETSDK1005 error...

Getting desperate :(

Thanks in advance for any help

P.S. - already checked question 70711153

8 Answers

I found the problem and it indeed had to do with restoring NuGet Packages, in that I have a connection to a corporate NuGet repository, and the call to it was breaking due to wrong credentials.

What was troubling was that the error did not identify the nature of problem with the connection or the username of the credentials getting refused.

On the logged in user popup dialog window, where the several used usernames are presented, there was one username that was required to re-enter its password.

That was all it took.

Visual Studio > Tools > Options > Azure Service Authentication. ReBuild and the NuGet Packages will be restored and build successful.

We had this issue in our Azure DevOps pipeline and it ended up being that the "NuGet Restore" task was using an old version of NuGet. You can see which version the pipeline is using if you check the logs for the "NuGet Restore" task and look for the "Detected NuGet" line. We:

  • added in the "NuGet Tool Installer" task before the "NuGet Restore" task
  • Under the "Version of NuGet.exe to install", list the version you want to use, or the minimum version (e.g. >=6.1.0)
  • (this step is possibly overkill) Under the "NuGet Restore" Task, check "Disable local cache"

I got the same error this morning. This worked for me: right click on solution explorer in visual studio -> 'Restore NuGet Packages'. Hope this helps.

I got the same error when publishing Web API to the cloud. Use Tools ->Command line -> Developer command prompt in Visual Studio 2022, enter AZ login, and after login, restart the visual studio, it is working for me again.

Had the same problem in Azure Devops, using a Windows 2019 build server with VisualStudio 2022

Error: ##[error]C:\Program Files\dotnet\sdk\6.0.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): Error NETSDK1005: Assets file 'C:\agent\vso_work\4\s<..>.API\obj\project.assets.json' doesn't have a target for 'net6.0'. Ensure that restore has run and that you have included 'net6.0' in the TargetFrameworks for your project.

Resolved by adding a "NuGet Tool Installer" using version >=6.0.0 Before the NuGet restore task

enter image description here

For me, I was getting this when updating my projects from .NET Core 3.1 to .NET 6. I had my .NET 6 code in another Git branch and when I switched from the main 3.1 branch to the 6 branch and then tried to build the solution, I would get that message.

After some trial and error, the solution that worked for me was doing the Git checkout and the restore via command line.

  1. Close the solution

  2. From the Developer Powershell (or using regular Powershell or the Visual Studio 2022 Command Prompt), navigate to the local directory that has your repo, and then:

    git checkout [branch name]

    dotnet restore

  3. Then back in Visual Studio, reopen the solution and build, which would work.

we got this problem when added cache on gitlab, and started to use dotnet restore, it happend because we missed the "runtime" parameter to the restore command,

- dotnet restore --packages .nuget --runtime win-x64
- dotnet publish --no-restore --runtime win-x64

For me this fix worked:

If you don't have the dotnet cmd line tool, download and install the .NET 6 SDK.

Open a cmd prompt and run the command:

 dotnet restore <path to your solution>

(for instance: dotnet restore c:\app\myapp.sln)

Related