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:
# Delete bin and obj folders
rm -Recurse -Force bin, obj
# Restore packages
dotnet restore
# Build project
dotnet build
# 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+):
# Update NuGet to latest version
dotnet tool update -g NuGet.CommandLine
# Check current versions
dotnet --version
nuget help | Select-String "NuGet Version"
For Azure DevOps pipelines, add a NuGet Tool Installer task:
- 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:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<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:
<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:
<Project>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<!-- Other publish settings -->
</PropertyGroup>
</Project>
6. Resolve Authentication Issues
If using private NuGet repositories, check your credentials:
- Open Visual Studio
- Go to Tools > Options > NuGet Package Manager > Package Sources
- Verify authentication for all configured package sources
- Re-enter credentials if prompted
7. IDE-Specific Solutions
# Close and reopen Visual Studio
# Then clean and rebuild solution
# 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:
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:
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst;net8.0</TargetFrameworks>
Prevention Tips
- Keep tools updated: Regularly update Visual Studio, .NET SDK, and NuGet
- Consistent configurations: Maintain identical settings across all environments
- Clean builds: Always clean solution before major changes or upgrades
- Version control: Include runtime configuration in source control
- Pipeline maintenance: Keep CI/CD pipeline tools updated
When to Seek Further Help
If these solutions don't resolve your issue:
- Check the Microsoft Developer Community for similar reports
- Verify there are no network or firewall issues blocking NuGet restores
- Ensure your project structure doesn't have external project references causing path issues
- 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.