-
-
Notifications
You must be signed in to change notification settings - Fork 110
Description
Description
When running the TUnit NUnit migration code fixer on projects that target multiple frameworks (e.g., <TargetFrameworks>net8.0;net9.0;net10.0;net462</TargetFrameworks>), the dotnet format analyzers command crashes with an exception related to linked file merging.
Steps to Reproduce
- Create a project with NUnit tests that targets multiple frameworks:
<TargetFrameworks>net8.0;net9.0;net10.0;net462</TargetFrameworks>
- Add TUnit packages
- Run
dotnet format analyzers --severity info --diagnostics TUNU0001
Expected Behavior
The migration should complete successfully for all target frameworks.
Actual Behavior
The command crashes with the following error:
Unhandled exception: System.AggregateException: One or more errors occurred.
(Changes must be within bounds of SourceText (Parameter 'changes'))
---> System.ArgumentException: Changes must be within bounds of SourceText (Parameter 'changes')
at Microsoft.CodeAnalysis.Text.SourceText.WithChanges(IEnumerable`1 changes)
at Microsoft.CodeAnalysis.LinkedFileMergeConflictCommentAdditionService.GetCommentChangesForDocument(...)
at Microsoft.CodeAnalysis.LinkedFileDiffMergingSession.MergeLinkedDocumentGroupAsync(...)
...
The migration process appears to identify files to format and attempts changes, but crashes when trying to merge the changes across multiple target frameworks.
Workaround
Temporarily change the project to a single target framework:
<TargetFramework>net8.0</TargetFramework>
<!-- <TargetFrameworks>net8.0;net9.0;net10.0;net462</TargetFrameworks> -->Then run the migration, and restore multi-targeting afterward.
Notes
This may be a dotnet format issue rather than a TUnit code fixer issue, but it significantly impacts the migration experience for projects with multiple target frameworks.
The error occurs in Microsoft.CodeAnalysis.LinkedFileMergeConflictCommentAdditionService, suggesting the issue is with how changes are being merged across the same files compiled for different target frameworks.
Possible Solutions
- Document the workaround in migration guide
- Investigate if the TUnit code fixer can make changes more compatible with linked file scenarios
- Report to dotnet/format if this is an upstream issue
Environment
- TUnit version: 1.9.91
- .NET version: .NET 8.0 (dotnet format from .NET 10.0.101 SDK)
- OS: Windows
- dotnet format version: (from .NET SDK 10.0.101)