.net-6.0visual-studio-2022

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


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

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...

P.S. - already checked question 70711153


Solution

  • 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.