Skip to content

[5.0] Let consumers choose the Roslyn version used by the testing framework - #1810

Merged
josefpihrt merged 8 commits into
mainfrom
feature/testing-framework-roslyn-version
Aug 16, 2026
Merged

[5.0] Let consumers choose the Roslyn version used by the testing framework#1810
josefpihrt merged 8 commits into
mainfrom
feature/testing-framework-roslyn-version

Conversation

@josefpihrt

@josefpihrt josefpihrt commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Problem

The Roslynator testing framework forced every test run onto a fixed Roslyn version (4.14.0), because Roslynator.Testing.* declared Microsoft.CodeAnalysis.* >= 4.14.0. Since NuGet dependency versions are minimums, a consumer whose analyzer targets an older Roslyn (e.g. the roslyn3.8 / roslyn4.7 buckets Roslynator itself ships) could not test against that version — NuGet unified the graph up to 4.14.0.

Change

  • Lower the testing packages' Roslyn floor to 3.8.0 so the effective version is determined by the consumer's own Microsoft.CodeAnalysis.* reference. Verified the Testing.* projects use no API newer than 3.8. build_core_and_testing compiles and packs those projects against 3.8.
  • Decouple Roslynator.Testing.Common from the Roslynator.Core package (its floor would otherwise leak back through). The ~6 internal helpers used (StringBuilderCache, Hash, the diagnostic comparers, ToReportDiagnostic) are duplicated into Testing.Common as internal types. Roslynator.Core's own published floor is unchanged.
  • Add RoslynatorTestRoslynVersion (default 5.0.0, matching this repo's analyzer Microsoft.CodeAnalysis.* floor after Bump Roslyn to 5.0 #1787) so the in-repo suite pins the Roslyn version used at test runtime.
    • This property only pins the test projects' Microsoft.CodeAnalysis.* PackageReference. It does not switch RoslynatorRoslynVersion / analyzer compilation.
    • This repo cannot pin the suite below 5.0: test projects ProjectReference analyzers that require Microsoft.CodeAnalysis.* >= 5.0.0.
    • CI does not run the analyzer suite at 3.8.0: that is the testing package compile floor for consumers, not a version this repo's analyzers can execute against.
  • Guard version-sensitive tests (SyntaxKindTests and tests using C# 12/13 features or newer-Roslyn formatter output) with ROSLYN_TEST_* defines in src/Tests/Directory.Build.props.
  • Also fix the roslyn4.7 DefineConstants list: ROSLYN_4_2,ROSLYN_4_4 used a comma, so ROSLYN_4_4 was never defined for that bucket. It is now semicolon-separated (already on main via Bump Roslyn to 5.0 #1787).

Consumer action required

A test project that relied on the implicit 4.14.0 should now add its own reference:

<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0" />

The chosen version raises the maximum C# the parser can accept; test sources still parse at CSharpParseOptions.Default (not Latest) unless you set parse options / LanguageVersion. The same note is in the Testing.CSharp.Xunit / MSTest NuGet readmes.

A test project that used Roslynator.Core types via the old transitive dependency must add an explicit Roslynator.Core package reference.

Verification

  • Full suite green at RoslynatorTestRoslynVersion=5.0.0 (default).
  • Packed nuspecs confirm Testing.Common/Testing.CSharp floor at 3.8.0 with no Roslynator.Core dependency; Roslynator.Core still floors at the product Roslyn version.

josefpihrt and others added 2 commits August 9, 2026 20:59
Lower the Roslyn dependency of the testing packages to 3.8.0 so the
effective Roslyn version is determined by the consumer's own
Microsoft.CodeAnalysis.* reference instead of being forced to a fixed
version.

- Decouple Roslynator.Testing.Common from the Roslynator.Core package by
  duplicating the handful of internal helpers it used.
- Add RoslynatorTestRoslynVersion so this repo's own test suite can run
  against a chosen Roslyn version; add a CI run at 4.7.0.
- Guard version-sensitive tests so the suite builds and passes at 4.7.0.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@josefpihrt josefpihrt left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review notes for making the testing framework’s Roslyn version consumer-selectable. Direction and changelog/breaking-change notes look strong; a few verification/CI clarifications.

Comment thread src/Directory.Build.props
Comment thread .github/workflows/build.yml Outdated
Comment thread CHANGELOG.md
Co-authored-by: Cursor <cursoragent@cursor.com>

@josefpihrt josefpihrt left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Detailed pass on the testing-framework Roslyn floor change. The approach is right: compile Testing.* against 3.8, drop the Roslynator.Core leak, pin this repo with RoslynatorTestRoslynVersion, and document the consumer PackageReference. CI is green at default 4.14 and at test_roslyn_versions 4.7.0; the earlier review nits on the 4.4 DefineConstants comma and the CI comment are addressed.

A few leftover product/docs issues before merge.

Comment thread CHANGELOG.md Outdated
Comment thread src/Tests/Analyzers.Tests/Analyzers.Tests.csproj Outdated
Comment thread src/Tests/Testing.CSharp.Xunit/docs/NuGetReadme.md Outdated
@josefpihrt josefpihrt changed the title Let consumers choose the Roslyn version used by the testing framework [5.0] Let consumers choose the Roslyn version used by the testing framework Aug 15, 2026
Josef Pihrt and others added 5 commits August 16, 2026 15:35
Move the Testing Framework changelog entry to Breaking (including the
Core reference break), centralize ROSLYN_TEST_* defines for all test
projects, and clarify Default vs Latest parse LanguageVersion in the
NuGet readmes. Also pin RoslynatorTestRoslynVersion to 5.0.0 after the
Roslyn 5.0 merge and drop the incompatible 4.7 test matrix cell.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The Unreleased #1787 bullet conflicted with the testing-package floor
at 3.8.0. CLI still targets 5.0.0; this repo's suite still runs at 5.0.0.

Co-authored-by: Cursor <cursoragent@cursor.com>
@josefpihrt
josefpihrt merged commit 8826515 into main Aug 16, 2026
17 checks passed
@josefpihrt
josefpihrt deleted the feature/testing-framework-roslyn-version branch August 16, 2026 14:41
This was referenced Aug 21, 2026
This was referenced Aug 24, 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

Development

Successfully merging this pull request may close these issues.

1 participant