Skip to content

fix(dotnet): fix dependency graph for multi-targeting and transitive deps#33908

Merged
FrozenPandaz merged 2 commits intomasterfrom
dotnet-deps-fixes
Dec 17, 2025
Merged

fix(dotnet): fix dependency graph for multi-targeting and transitive deps#33908
FrozenPandaz merged 2 commits intomasterfrom
dotnet-deps-fixes

Conversation

@AgentEnder
Copy link
Copy Markdown
Member

Current Behavior

Two issues with the .NET dependency graph:

  1. Issue @nx/dotnet missing dependencies in case multi output targets #33653: When a .NET project uses multi-targeting ( plural), its project reference dependencies disappear from the Nx graph.
  2. Issue Graph shows transitive dependencies for projects added via @nx/dotnet #33397: Transitive dependencies are incorrectly shown as direct dependencies. For example, if A → B → C, the graph shows A depending on both B and C, when it should only show A → B.

Expected Behavior

  1. Multi-targeting projects should correctly show their dependencies in the graph.
  2. Only direct dependencies should be shown, not transitive ones. Nx handles transitive dependencies through the dependency chain.

Solution

Multi-targeting fix (#33653)

MSBuild creates multiple nodes for multi-targeting projects:

  • An "outer build" with TargetFrameworks set but TargetFramework empty
  • "Inner builds" for each target framework with TargetFramework set

The fix groups nodes by project file path and prefers inner builds (which have properly resolved references) over outer builds.

Transitive dependency fix (#33397)

Changed from using ProjectGraphNode.ProjectReferences (which includes transitive dependencies in multi-targeting scenarios) to ProjectInstance.GetItems("ProjectReference") which returns only direct references defined in the project file.

Related Issue(s)

Fixes #33653
Fixes #33397

AgentEnder and others added 2 commits December 17, 2025 14:47
This commit fixes two related issues with the .NET dependency graph:

1. Issue #33397: Transitive dependencies were incorrectly shown as direct
   dependencies in the project graph. Changed from using
   ProjectGraphNode.ProjectReferences (which includes transitive deps in
   multi-targeting scenarios) to ProjectInstance.GetItems("ProjectReference")
   which returns only direct references defined in the project file.

2. Issue #33653: Multi-targeting projects (using TargetFrameworks plural)
   were losing their dependencies. The fix groups nodes by project file path
   and prefers inner builds (which have TargetFramework set) over outer builds
   for configuration, ensuring proper reference resolution.

Added e2e tests to verify:
- Multi-targeting projects correctly show their dependencies
- Only direct dependencies appear in the graph, not transitive ones

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Dec 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
nx-dev Ready Ready Preview Dec 17, 2025 8:51pm

@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 17, 2025

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 27a8023
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/694317d9f6d50a0008d05979
😎 Deploy Preview https://deploy-preview-33908--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Dec 17, 2025

View your CI Pipeline Execution ↗ for commit 27a8023

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 5m 5s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2m 25s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 12s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-17 21:01:53 UTC

@FrozenPandaz FrozenPandaz merged commit c7cdd2a into master Dec 17, 2025
20 checks passed
@FrozenPandaz FrozenPandaz deleted the dotnet-deps-fixes branch December 17, 2025 23:22
FrozenPandaz pushed a commit that referenced this pull request Dec 18, 2025
…deps (#33908)

## Current Behavior

  Two issues with the .NET dependency graph:

1. Issue #33653: When a .NET project uses multi-targeting
(<TargetFrameworks> plural), its project reference dependencies
disappear from the Nx graph.
2. Issue #33397: Transitive dependencies are incorrectly shown as direct
dependencies. For example, if A → B → C, the graph shows A depending on
both B and C, when it should only show A → B.

##  Expected Behavior

1. Multi-targeting projects should correctly show their dependencies in
the graph.
2. Only direct dependencies should be shown, not transitive ones. Nx
handles transitive dependencies through the dependency chain.

 ### Solution

  Multi-targeting fix (#33653)

  MSBuild creates multiple nodes for multi-targeting projects:
  - An "outer build" with TargetFrameworks set but TargetFramework empty
  - "Inner builds" for each target framework with TargetFramework set

The fix groups nodes by project file path and prefers inner builds
(which have properly resolved references) over outer builds.

 ### Transitive dependency fix (#33397)

Changed from using ProjectGraphNode.ProjectReferences (which includes
transitive dependencies in multi-targeting scenarios) to
ProjectInstance.GetItems("ProjectReference") which returns only direct
references defined in the project file.

 ## Related Issue(s)

  Fixes #33653
  Fixes #33397

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@nx/dotnet missing dependencies in case multi output targets Graph shows transitive dependencies for projects added via @nx/dotnet

2 participants