Skip to content

[msbuild] Fix building binding projects with 'dotnet build /t:Compile'#25914

Open
rolfbjarne wants to merge 1 commit into
mainfrom
dev/rolf/hot-reload-binding-projects
Open

[msbuild] Fix building binding projects with 'dotnet build /t:Compile'#25914
rolfbjarne wants to merge 1 commit into
mainfrom
dev/rolf/hot-reload-binding-projects

Conversation

@rolfbjarne

@rolfbjarne rolfbjarne commented Jul 2, 2026

Copy link
Copy Markdown
Member

'dotnet watch' builds the 'Compile' target directly (it runs 'dotnet build /t:Compile'). For binding projects this failed, because the binding-project override of CompileDependsOn prepends _GenerateBindings (which in turn runs _CompileApiDefinitions) before $(CompileDependsOn) - and $(CompileDependsOn) is where the default ResolveReferences lives.

During a normal build ResolveReferences runs earlier as part of CoreBuild, so @(ReferencePath) is already populated when the binding targets run. But when the Compile target is built directly, nothing runs ResolveReferences first, so _CompileApiDefinitions compiles the API definitions with no references at all and fails with thousands of errors ("Predefined type 'System.Void' is not defined", missing System.Runtime, NSObject, ExportAttribute, etc.).

Fix this by adding ResolveReferences to the front of the binding-project CompileDependsOn override, so references are always resolved before the binding-generation targets that need them.

Also add a unit test (BuildBindingsTestWithCompileTarget) that builds a binding project with '/t:Compile'.

Contributes towards https://devdiv.visualstudio.com/DevDiv/_workitems/edit/3024114.

'dotnet watch' builds the 'Compile' target directly (it runs
'dotnet build /t:Compile'). For binding projects this failed, because the
binding-project override of CompileDependsOn prepends _GenerateBindings (which
in turn runs _CompileApiDefinitions) before $(CompileDependsOn) - and
$(CompileDependsOn) is where the default ResolveReferences lives.

During a normal build ResolveReferences runs earlier as part of CoreBuild, so
@(ReferencePath) is already populated when the binding targets run. But when the
Compile target is built directly, nothing runs ResolveReferences first, so
_CompileApiDefinitions compiles the API definitions with no references at all
and fails with thousands of errors ("Predefined type 'System.Void' is not
defined", missing System.Runtime, NSObject, ExportAttribute, etc.).

Fix this by adding ResolveReferences to the front of the binding-project
CompileDependsOn override, so references are always resolved before the
binding-generation targets that need them.

Also add a unit test (BuildBindingsTestWithCompileTarget) that builds a binding
project with '/t:Compile'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 2, 2026 17:36
@rolfbjarne rolfbjarne requested a review from mauroa as a code owner July 2, 2026 17:36
@rolfbjarne rolfbjarne removed the request for review from mauroa July 2, 2026 17:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes SDK-style binding projects failing when building the Compile target directly (notably dotnet watch, which runs dotnet build /t:Compile). The failure occurred because binding-generation ran before references were resolved, leaving @(ReferencePath) empty during API definition compilation.

Changes:

  • Prepend ResolveReferences to the binding-project CompileDependsOn override so binding-generation targets have @(ReferencePath) populated even when /t:Compile is invoked directly.
  • Add a unit test that builds a binding project with target: "Compile" across Apple platforms to prevent regressions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
msbuild/Xamarin.Shared/Xamarin.Shared.targets Ensures ResolveReferences runs before binding-generation when building /t:Compile, fixing missing-reference compilation failures.
tests/dotnet/UnitTests/ProjectTest.cs Adds coverage for building a binding project via /t:Compile (dotnet watch scenario).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #78079fa] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 78079fa8cbfa2536b4a6e4347c4adb321d6d7faf [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #78079fa] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 78079fa8cbfa2536b4a6e4347c4adb321d6d7faf [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 78079fa8cbfa2536b4a6e4347c4adb321d6d7faf [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #78079fa] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 78079fa8cbfa2536b4a6e4347c4adb321d6d7faf [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #78079fa] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

1 tests crashed, 1 tests failed, 197 tests passed.

Failures

❌ dotnettests tests (tvOS)

🔥 Failed catastrophically on VSTS: test results - dotnettests_tvos (no summary found).

Html Report (VSDrops) Download

❌ monotouch tests (iOS)

1 tests failed, 17 tests passed.

Failed tests

  • monotouch-test/iOS - simulator/Release (compat inline Class.GetHandle): Failed

Html Report (VSDrops) Download

Successes

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 17 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 18 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 78079fa8cbfa2536b4a6e4347c4adb321d6d7faf [PR build]

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants