Skip to content

Fixing NETSDK1005: Assets file project.assets.json doesn't have a target error

This article addresses the common NETSDK1005 error that occurs when building .NET projects, particularly after upgrading Visual Studio or .NET versions. The error indicates that the project's assets file is missing a target framework specification.

Problem Overview

The NETSDK1005 error typically appears as:

Error NETSDK1005
Assets file '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.

This error occurs when the NuGet package restore process fails to properly generate the project.assets.json file with the correct target framework information, even when your .csproj file has the correct target framework specified.

Root Cause

The error is typically caused by one of these scenarios:

  • NuGet restore failures due to authentication issues or version mismatches
  • Incomplete or incorrect target framework specifications
  • Mismatched settings between projects and publish profiles
  • Outdated build artifacts that need cleaning
  • Runtime identifier mismatches

Solutions

1. Perform Complete Clean and Restore

The most reliable first step is to completely clean and restore your project:

bash
# Delete bin and obj folders
rm -Recurse -Force bin, obj

# Restore packages
dotnet restore

# Build project
dotnet build
bash
# Remove bin and obj directories
Remove-Item -Recurse -Force bin, obj

# Restore and build
dotnet restore
dotnet build

2. Update NuGet and MSBuild Versions

Ensure you're using compatible versions of NuGet (5.8+) and MSBuild (16.8+):

bash
# Update NuGet to latest version
dotnet tool update -g NuGet.CommandLine
bash
# Check current versions
dotnet --version
nuget help | Select-String "NuGet Version"

For Azure DevOps pipelines, add a NuGet Tool Installer task:

yaml
- task: NuGetToolInstaller@1
  inputs:
    versionSpec: '>=6.0.0'
    checkLatest: true

3. Verify Target Framework Configuration

Ensure your .csproj file has the correct target framework specification:

xml
<PropertyGroup>
  <TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
xml
<PropertyGroup>
  <TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

WARNING

Note the difference between TargetFramework (singular) for single targets and TargetFrameworks (plural) for multiple targets.

4. Check Runtime Identifiers

Add appropriate runtime identifiers for your target environments:

xml
<PropertyGroup>
  <RuntimeIdentifiers>win-x64;win-x86;linux-x64</RuntimeIdentifiers>
</PropertyGroup>

5. Fix Publish Profile Configuration

If the error occurs during publishing, ensure your publish profile (.pubxml) matches your project's target framework:

xml
<Project>
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <!-- Other publish settings -->
  </PropertyGroup>
</Project>

6. Resolve Authentication Issues

If using private NuGet repositories, check your credentials:

  1. Open Visual Studio
  2. Go to Tools > Options > NuGet Package Manager > Package Sources
  3. Verify authentication for all configured package sources
  4. Re-enter credentials if prompted

7. IDE-Specific Solutions

bash
# Close and reopen Visual Studio
# Then clean and rebuild solution
bash
# Sometimes using MSBuild directly helps
msbuild YourSolution.sln /t:Restore
msbuild YourSolution.sln /t:Build

8. Check for Framework/Runtime Mismatches

Ensure consistency between:

  • Project target framework
  • Publish profile target framework
  • Runtime identifiers
  • Any CI/CD pipeline configurations

Azure DevOps Specific Solutions

For pipeline failures, implement these steps:

yaml
steps:
- task: NuGetToolInstaller@1
  inputs:
    versionSpec: '>=6.0.0'
    
- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'select'
    
- task: VSBuild@1
  inputs:
    solution: '**/*.sln'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package'
    platform: 'Any CPU'
    configuration: 'Release'

Platform-Specific Considerations

INFO

For MAUI, Xamarin, or iOS/Android projects, ensure you include all necessary target frameworks:

xml
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst;net8.0</TargetFrameworks>

Prevention Tips

  1. Keep tools updated: Regularly update Visual Studio, .NET SDK, and NuGet
  2. Consistent configurations: Maintain identical settings across all environments
  3. Clean builds: Always clean solution before major changes or upgrades
  4. Version control: Include runtime configuration in source control
  5. Pipeline maintenance: Keep CI/CD pipeline tools updated

When to Seek Further Help

If these solutions don't resolve your issue:

  1. Check the Microsoft Developer Community for similar reports
  2. Verify there are no network or firewall issues blocking NuGet restores
  3. Ensure your project structure doesn't have external project references causing path issues
  4. Check for any malformed XML in your project files

By methodically applying these solutions, you should be able to resolve the NETSDK1005 error and successfully build your .NET projects.