When building or publishing a .NET 8 Windows desktop application (Windows Forms or WPF), encountering an abrupt failure at the Publish stage—even when your project builds cleanly—is a common and frustrating bottleneck.
The compiler outputs an error similar to the following:
Build started...
1>------ Publish started: Project: DesktopApp, Configuration: Release Any CPU ------
1>Assets file 'C:\Projects\DesktopApp\obj\project.assets.json' doesn't have a target for 'net8.0-windows7.0'.
Ensure that restore has run and that you have included 'net8.0-windows7.0' in the TargetFrameworks for your project.
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
What makes this error particularly confusing is that your .csproj file likely specifies <TargetFramework>net8.0-windows</TargetFramework>, with no mention of 7.0 anywhere in your source code. Furthermore, Visual Studio reports Build: 1 up-to-date, yet Publish immediately aborts.
This guide breaks down the internal MSBuild and NuGet mechanics behind this error and provides end-to-end solutions—from local workspace cleanup and multi-project architecture fixes to self-contained single-file publishing and CI/CD pipeline hardening.
1. Anatomy of the Error: Under the Hood of MSBuild & NuGet
To resolve and prevent this issue permanently, it helps to understand how the .NET SDK evaluates Target Framework Monikers (TFMs), resolves platform versions, and caches dependency graphs.
A. Target Framework Moniker (TFM) Aliasing & Platform Resolution
In modern .NET (.NET 5+), OS-specific Target Framework Monikers follow the canonical syntax <tfm>-<os><version>.
When you declare:
<TargetFramework>net8.0-windows</TargetFramework>
net8.0-windows is an unversioned shorthand alias. During MSBuild property evaluation (Microsoft.NET.TargetFrameworkInference.targets), the .NET SDK automatically resolves this alias to the default minimum supported Windows OS version for .NET 8, which is Windows 7 (net8.0-windows7.0).
Internally, NuGet, the C# compiler (csc.exe), and the ResolvePackageAssets MSBuild task never operate against net8.0-windows—they always evaluate against the resolved canonical TFM (net8.0-windows7.0).
B. Anatomy of obj/project.assets.json
When dotnet restore runs, NuGet resolves all package dependencies, transitive references, framework targeting packs (Microsoft.WindowsDesktop.App.WindowsForms or Microsoft.WindowsDesktop.App.WPF), and Runtime Identifiers (RIDs), serializing the resulting dependency graph to obj/project.assets.json.
Inside project.assets.json, NuGet constructs a "targets" dictionary keyed by the resolved TFM and any restored RIDs:
{
"version": 3,
"targets": {
"net8.0-windows7.0": {
"System.Drawing.Common/8.0.0": { ... }
},
"net8.0-windows7.0/win-x64": {
"System.Drawing.Common/8.0.0": { ... }
}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Projects\\DesktopApp\\DesktopApp.csproj",
"projectName": "DesktopApp",
"outputPath": "C:\\Projects\\DesktopApp\\obj\\",
"frameworks": {
"net8.0-windows7.0": {
"targetAlias": "net8.0-windows"
}
}
}
}
}
If project.assets.json was generated under a different TFM (e.g., after upgrading from .NET 6 or .NET 7), after moving/renaming a project directory, or without a target Runtime Identifier (win-x64), the ResolvePackageAssets MSBuild task throws error NETSDK1005 because it cannot locate the exact target key inside "targets".
C. Why Build Succeeds While Publish Fails
Fast Up-To-Date Check (FUTDC): Visual Studio uses an optimization heuristic during standard builds. If no .cs or .csproj timestamps have changed since the last build, Visual Studio bypasses MSBuild completely (1 up-to-date).
Strict Publish Evaluation: Invoking Publish executes a distinct set of MSBuild targets (_DeploymentComputeClickOnceManifestInfo, ResolvePackageAssets, and RID-specific asset resolution). If you are publishing a Self-Contained executable or targeting a specific architecture (win-x64), Publish demands a RID-specific dependency graph (net8.0-windows7.0/win-x64) inside project.assets.json that a standard Any CPU Debug build never generated.
2. Step-by-Step Resolution Guide
Step 1: Purge Stale Build Artifacts (bin and obj)
Visual Studio's built-in Build > Clean Solution command only deletes compiled binary outputs (.dll, .exe, .pdb); it intentionally preserves obj/project.assets.json to accelerate subsequent builds. You must purge the obj directory manually.
Close Visual Studio (or ensure no background dotnet.exe or MSBuild.exe processes are holding file locks).
Delete both the bin and obj folders from your project directory.
Open a terminal in the project root and run a forced restore and publish:
dotnet restore --force
dotnet publish -c Release
For multi-project solutions, run a recursive PowerShell cleanup command from the solution root before restoring:
Get-ChildItem -Include bin,obj -Recurse -Force | Remove-Item -Force -Recurse
dotnet restore --force
Step 2: Audit Your Publish Profile (.pubxml)
If standard builds succeed (Build succeeded: 0 failed) and the error only triggers when clicking Publish in Visual Studio, your saved Publish Profile is almost certainly out of sync with your .csproj file. This frequently happens after upgrading a project from .NET 6 or .NET 7 to .NET 8.
In Visual Studio Solution Explorer, expand Properties > PublishProfiles.
Open your active .pubxml file (e.g., FolderProfile.pubxml).
Inspect <TargetFramework>, <RuntimeIdentifier>, and <PublishDir>:
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net8.0-windows\win-x64\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<!-- Must match your .csproj TargetFramework -->
<TargetFramework>net8.0-windows7.0</TargetFramework>
<!-- Required when SelfContained is true -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
</Project>
If <TargetFramework> inside the .pubxml still reads net6.0-windows or net7.0-windows, update it to net8.0-windows7.0, save the file, and run dotnet restore.
Step 3: Explicitly Define the Windows Platform Version in .csproj
If your team works across varying Visual Studio versions, containerized build agents, or mixed SDK patch releases, relying on the net8.0-windows shorthand can trigger target resolution discrepancies. Explicitly declaring net8.0-windows7.0 (or net8.0-windows10.0.19041.0 if calling modern Windows 10/11 WinRT APIs) eliminates all implicit aliasing:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<!-- Explicit TFM prevents alias resolution mismatches -->
<TargetFramework>net8.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationHighDpiMode>SystemAware</ApplicationHighDpiMode>
<AssemblyName>DesktopApp</AssemblyName>
<AssemblyTitle>Desktop Application</AssemblyTitle>
<Product>Desktop Application</Product>
</PropertyGroup>
</Project>
3. Advanced Scenarios: Multi-Project Solutions & Single-File RIDs
A. Multi-Project Solutions (Class Library + Desktop App)
In layered architectures where a net8.0-windows7.0 desktop executable references a shared net8.0 class library (e.g., Core.dll or DataAccess.dll), NuGet builds a unified dependency graph across all project references.
If you change the target framework or Runtime Identifier in the executable project without restoring the entire solution, the referenced class library's obj/project.assets.json becomes out of sync with the parent executable.
Best Practice: Always execute dotnet restore against the .sln (Solution) file, never solely against an individual .csproj file:
dotnet restore YourSolution.sln --force
dotnet publish src/DesktopApp/DesktopApp.csproj -c Release
B. Self-Contained & Single-File Publishing (Runtime Identifier Errors)
Windows desktop applications are routinely distributed as Self-Contained Single-File executables so end users do not need to pre-install the .NET 8 Desktop Runtime.
When publishing with --self-contained true or <PublishSingleFile>true</PublishSingleFile>, NuGet must restore runtime packs for a specific Runtime Identifier (RID) such as win-x64, win-x86, or win-arm64.
Running the following sequence will fail immediately:
dotnet restore
dotnet publish -c Release -r win-x64 --self-contained true --no-restore
Because dotnet restore was invoked without -r win-x64, NuGet never populated the net8.0-windows7.0/win-x64 section in project.assets.json.
Solution: Declare <RuntimeIdentifiers> in .csproj
To guarantee that every standard dotnet restore automatically generates asset graphs for your target Windows architectures, add <RuntimeIdentifiers> (plural) to your .csproj:
<PropertyGroup>
<TargetFramework>net8.0-windows7.0</TargetFramework>
<RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
With <RuntimeIdentifiers> declared in the project file, NuGet pre-populates both win-x64 and win-x86 targets inside project.assets.json on every restore.
4. Diagnosing Stubborn Mismatches with MSBuild Binary Logs
If you have purged bin/obj, updated .pubxml, and explicitly set <TargetFramework>, yet the error persists, capture an MSBuild binary log (.binlog) to inspect the exact properties passed to ResolvePackageAssets:
dotnet publish -c Release -bl:publish.binlog
Open publish.binlog using the free MSBuild Structured Log Viewer and search for ResolvePackageAssets. Inspect the following input parameters:
TargetFrameworkMoniker: Verify it evaluates to .NETCoreApp,Version=v8.0.
TargetPlatformMoniker: Verify it evaluates to Windows,Version=7.0.
RuntimeIdentifier: Check whether a hidden environment variable (such as RuntimeIdentifier set globally on a build machine) is overriding your project settings.
ProjectAssetsFile: Confirm the path points to the expected obj\project.assets.json and not a redirected BaseIntermediateOutputPath folder.
5. Hardening CI/CD Pipelines & Team Workflows
To ensure no developer or build agent encounters NETSDK1005 again, enforce these four engineering standards across your repository:
1. Enforce Strict .gitignore Rules
Never commit bin/ or obj/ directories to version control. Pulling an obj/project.assets.json generated on another developer's machine (with different local NuGet cache paths or SDK patch versions) guarantees target mismatches.
# Build artifacts & NuGet asset caches
[Bb]in/
[Oo]bj/
*.user
*.suo
*.binlog
2. Match Restore and Publish Arguments in CI/CD
In GitHub Actions, Azure DevOps, or automated build scripts, ensure dotnet restore and dotnet publish share identical Runtime Identifier (-r) and configuration flags—or omit --no-restore so dotnet publish handles restoration atomically:
# GitHub Actions Example for .NET 8 Windows Desktop Publishing
name: Build and Publish Desktop Release
on:
push:
tags:
- 'v*'
jobs:
publish-windows:
runs-on: windows-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup .NET 8 SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore Dependencies (with RID)
run: dotnet restore DesktopApp.sln -r win-x64
- name: Publish Self-Contained Single-File Executable
run: >
dotnet publish src/DesktopApp/DesktopApp.csproj
-c Release
-r win-x64
--self-contained true
-p:PublishSingleFile=true
-p:IncludeNativeLibrariesForSelfExtract=true
--no-restore
-o ./artifacts/win-x64
3. Pin the .NET SDK Version via global.json
When multiple major versions of the .NET SDK (e.g., .NET 6, .NET 8, .NET 9) are installed side-by-side on developer workstations or build agents, MSBuild may evaluate target platform defaults using the newest installed SDK. Pin your SDK version at the repository root using global.json:
{
"sdk": {
"version": "8.0.400",
"rollForward": "latestFeature"
}
}
4. Centralize Build Properties with Directory.Build.props
For repositories containing multiple desktop executables, test projects, or shared libraries, place a Directory.Build.props file at the solution root to enforce consistent target framework and runtime identifier defaults across every project automatically:
<Project>
<PropertyGroup>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
</PropertyGroup>
</Project>
Summary Troubleshooting Matrix
Symptom | Underlying Cause | Definitive Fix |
Error appears after renaming project, moving folders, or switching Git branches | Stale obj/project.assets.json cached from previous state | Delete all bin/ and obj/ folders, then run dotnet restore --force |
Build succeeds (1 up-to-date), but Publish fails
| Stale .pubxml profile targeting an older .NET version (net6.0/net7.0) | Update <TargetFramework> inside Properties/PublishProfiles/*.pubxml |
Error triggers only when publishing --self-contained or -r win-x64 | project.assets.json lacks the RID-specific dependency graph
| Add <RuntimeIdentifiers>win-x64</RuntimeIdentifiers> to .csproj and restore |
Error occurs in a multi-project solution | Referenced class library obj/ assets are out of sync with main app | Run dotnet restore against the .sln file rather than a single .csproj |
Inconsistent behavior across developer machines or CI agents | Implicit aliasing of net8.0-windows vs explicit net8.0-windows7.0 | Explicitly set <TargetFramework>net8.0-windows7.0</TargetFramework> and pin global.json |
.NET 8project.assets.jsonNETSDK1005MSBuildNuGet restoreWindows desktop publishingRuntime Identifier
Join the conversation! Your thoughts help the community grow.