Add MVVM Toolkit code fixer for Roslyn 5.0#1171
Merged
Sergio0694 merged 5 commits intomainfrom Mar 17, 2026
Merged
Conversation
Add a new CommunityToolkit.Mvvm.CodeFixers.Roslyn5000.csproj targeting net10.0 with ImplicitUsings and Nullable enabled, and include the project in dotnet.slnx. This adds a Roslyn5000-specific CodeFixers project to the solution so it can be built and discovered by the solution tooling.
Replace inline project properties in the Roslyn5000 csproj with imports of the shared props and projitems to centralize configuration. Also add a new conditional DefineConstants in CommunityToolkit.Mvvm.CodeFixers.props to define ROSLYN_5_0_0_OR_GREATER when MvvmToolkitSourceGeneratorRoslynVersion >= 5.0.0, enabling feature flags for Roslyn 5.0.
Use the Roslyn 5+ API when available to determine the C# language version. Add a conditional compilation branch that calls Compilation.HasLanguageVersionAtLeastEqualTo(LanguageVersion.CSharp14) when ROSLYN_5_0_0_OR_GREATER is defined, and fall back to the previous IsLanguageVersionPreview() check otherwise. This avoids generating invalid code on older Roslyn builds while correctly detecting C#14+ in newer toolchains.
Add a ProjectReference to CommunityToolkit.Mvvm.CodeFixers.Roslyn5000 (ReferenceOutputAssembly="false") and update the packaged analyzer entry for roslyn5.0 to point at the Roslyn5000 DLL. This ensures the Roslyn 5.0 code fixers are built and included in the package analyzers folder for roslyn5.0 compatibility.
Update unit tests to run against different C# language versions: add DataRow(LanguageVersion.Preview) to each test and, under ROSLYN_5_0_0_OR_GREATER, add DataRow(LanguageVersion.CSharp14). Change test methods to accept a LanguageVersion parameter and use it when constructing CSharpCodeFixTest (replace hardcoded LanguageVersion.Preview). Conditional compilation preserves compatibility with older Roslyn targets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new multi-targeted code fixer for the MVVM Toolkit, so that it works correctly with C# 14.