Skip to content

Fix MSB3030 when RestoreDoNotWriteDependencyGraphSpec is enabled - #12169

Open
Goldloli wants to merge 1 commit into
dotnet:mainfrom
Goldloli:fix/restore-do-not-write-dgspec
Open

Goldloli wants to merge 1 commit into
dotnet:mainfrom
Goldloli:fix/restore-do-not-write-dgspec

Conversation

@Goldloli

@Goldloli Goldloli commented Nov 27, 2026 •

Copy link
Copy Markdown

Fixes #12108

Description

RestoreDoNotWriteDependencyGraphSpec=true stops NuGet from writing <project>.nuget.dgspec.json into MSBuildProjectExtensionsPath. GenerateTemporaryTargetAssembly in Microsoft.WinFX.targets nevertheless added that file to _SourceGeneratedNuGetPropsAndTargets unconditionally, so the Copy task that mirrors the outer project's NuGet files for the temporary WPF project failed with:

error MSB3030: Could not copy the file "...\obj\<project>.csproj.nuget.dgspec.json"

The build stopped before markup compilation, making the opt-in property unusable for WPF projects. The dgspec item is now only added when the restore is allowed to produce it, so the copy stays as before by default and is skipped when the file cannot exist.

Customer Impact

Anyone enabling RestoreDoNotWriteDependencyGraphSpec (added for NuGet/Home#14114) on a WPF project gets a hard build failure with no workaround other than turning the property off again. Dotnet SDK 10.0.4xx is affected; there is no WPF-specific workaround because the failing Copy lives in the WPF build targets.

Regression

No. The property is new in the 10.0.4xx SDK and this target predates it; this is a missing interaction rather than a change in previously working behaviour. Projects that do not set the property copy the same files as before.

Testing

Reproduced and verified on macOS with .NET SDK 10.0.402, EnableWindowsTargeting=true:

  1. dotnet new wpf -n wpfrepro, then <RestoreDoNotWriteDependencyGraphSpec>true</RestoreDoNotWriteDependencyGraphSpec> in the project file.
  2. dotnet build before the change:
    Microsoft.WinFX.targets(408,7): error MSB3030: Could not copy the file ".../obj/wpfrepro.csproj.nuget.dgspec.json" — build failed.
  3. dotnet build with the patched Microsoft.WinFX.targets, same project and same SDK: Build succeeded, 0 warnings, 0 errors.
  4. Default path without the property, patched targets: build succeeds and obj/wpfrepro.csproj.nuget.dgspec.json is still generated and copied, so the existing behaviour is unchanged.

The A/B used the identical project file and MSBuild invocation, with only the targets file switched, so the difference is attributable to this change. The task assembly was pinned to the SDK's own PresentationBuildTasks.dll; that pinning is part of the throwaway test project only and is not in the diff.

Not run: the repository's own build.cmd / test.cmd on Windows, which needs a Windows host. The change is confined to two ItemGroups in the build targets and does not touch the task implementations.

Risk

Low. The modification only narrows when the dgspec file is copied, under the same IncludePackageReferencesDuringMarkupCompilation guard as before. When the property is unset (the default), the item list is identical to the current one, so existing builds follow exactly the previous code path.

Microsoft Reviewers: Open in CodeFlow

With RestoreDoNotWriteDependencyGraphSpec=true the restore no longer
writes <project>.nuget.dgspec.json, but GenerateTemporaryTargetAssembly
still added it to the items it copies for the temporary WPF project. The
unconditional Copy then failed with MSB3030 and the build stopped before
markup compilation.

Only add the dependency graph spec to the copied files when it is
actually produced, leaving the default behaviour unchanged.
@Goldloli
Goldloli requested a review from a team November 27, 2026 11:40
@Goldloli
Goldloli requested a review from a team as a code owner November 27, 2026 11:40
@dotnet-policy-service dotnet-policy-service Bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Nov 27, 2026
@lindexi

lindexi commented Nov 30, 2026

Copy link
Copy Markdown
Member

I cherry-picked your changes into my WpfRuntime repo, the GitHub Actions CI build passed and produced a NuGet package. You can now install the following package in your project to test out / use your fix:

<PackageReference Include="WpfLab.WpfRuntime" Version="1.1.0.1-test.20261130091851.cf0e0b" />

See: WpfLab/WpfRuntime#48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WPF build fails with MSB3030 when NuGet dependency graph spec writing is disabled

2 participants