Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 11, 2025

This PR fixes a critical deadlock issue in Visual Studio when building React Native Windows C++ projects. The problem occurred when MSBuild targets called the Restore target during the BeforeResolveReferences phase of Visual Studio builds.

Problem

The BeforeResolveReferences target in both Microsoft.ReactNative.Common.targets and vnext/Directory.Build.targets was calling the NuGet Restore target when BuildingInsideVisualStudio was true. This caused several issues:

  1. Deadlocks: The restore task accesses UI thread-bound components without proper Joint Task Factory (JTF) synchronization, leading to Visual Studio deadlocks
  2. Contract violation: Restore and build have a contract where restore must complete before build starts - calling restore during build violates this contract
  3. Performance issues: Network calls during restore on the UI thread cause delays and potential hangs

Solution

Removed the problematic BeforeResolveReferences targets that were calling MSBuild tasks with Targets="Restore". Visual Studio has its own built-in NuGet package restoration mechanisms that handle this properly without the deadlock risk.

The fix includes:

  • Complete removal of BeforeResolveReferences targets from both affected files
  • Added comprehensive comments explaining why the restore calls were problematic
  • Preserved all other MSBuild functionality including validation targets and NuGet configuration

Files Changed

  • vnext/PropertySheets/External/Microsoft.ReactNative.Common.targets
  • vnext/Directory.Build.targets

Both files had identical problematic patterns that have been resolved.

Fixes #15108.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Microsoft Reviewers: Open in CodeFlow

- Remove MSBuild calls to Restore target from BeforeResolveReferences in VS builds
- Add explanatory comments documenting why restore calls cause deadlocks
- Preserve all other functionality while fixing the deadlock issue
- Visual Studio will handle NuGet restoration through its own mechanisms

Co-authored-by: anupriya13 <[email protected]>
@Copilot Copilot AI changed the title [WIP] Calling the restore target in VS leads to a deadlock Fix Visual Studio deadlock caused by restore target calls in BeforeResolveReferences Sep 11, 2025
@Copilot Copilot AI requested a review from anupriya13 September 11, 2025 04:36
Copilot finished work on behalf of anupriya13 September 11, 2025 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calling the restore target in VS leads to a deadlock
2 participants