Skip to content

Conversation

@thomhurst
Copy link
Owner

Summary

  • Fix namespace verification in migration analyzers to handle partial semantic resolution failures
  • Ensure consistent code fixer output across different TFMs in multi-targeting projects

Problem

When running migration code fixers (TUNU0001, TUXU0001) on multi-targeting projects, Roslyn inserts merge conflict markers when different TFMs produce different transformation outputs:

<<<<<<< TODO: Unmerged change from project 'Project(net462)', Before:
Assert.AreEqual(4, expected);
=======
Assert.AreEqual(expected).IsEqualTo(4);
>>>>>>> After
await Assert.That(expected).IsEqualTo(4);

This is a known Roslyn/dotnet format behavior. When semantic analysis fails for some TFMs (due to different package versions, missing dependencies, or inconsistent semantic models), the namespace verification methods return false instead of true, causing different transformation outputs per TFM.

Solution

Modified the namespace verification methods in all three migration analyzers to only return false when we positively know the namespace does NOT match the expected framework:

  • XUnitTwoPhaseAnalyzer: IsXUnitAssertion() now returns true if namespace is null or matches "Xunit.Assert"
  • NUnitTwoPhaseAnalyzer: VerifyNUnitNamespace() now returns true if namespace is null or matches "NUnit.Framework"
  • MSTestTwoPhaseAnalyzer: VerifyMSTestNamespace() now returns true if namespace is null or matches "Microsoft.VisualStudio.TestTools.UnitTesting"

Test plan

  • Build passes
  • xUnit migration tests pass (177 passed, 3 skipped)
  • NUnit migration tests pass (411 passed)
  • MSTest migration tests pass (117 passed)

Fixes #4612
Fixes #4613

When running migration code fixers on multi-targeting projects, Roslyn
inserts merge conflict markers when different TFMs produce different
transformation outputs. This happens because semantic analysis can fail
for some TFMs due to different package versions or missing dependencies.

The fix modifies the namespace verification methods in all three
migration analyzers (xUnit, NUnit, MSTest) to only return false when
the namespace is positively NOT the target framework. When namespace
resolution fails (returns null), we now assume the syntax match is
correct and return true, ensuring consistent behavior across TFMs.

Fixes #4612
Fixes #4613
@claude
Copy link
Contributor

claude bot commented Jan 29, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@thomhurst thomhurst merged commit bb263e1 into main Jan 29, 2026
12 of 13 checks passed
@thomhurst thomhurst deleted the fix/code-fixer-merge-conflict-markers branch January 29, 2026 22:23
This was referenced Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants