This document explains how AutoLoggerMessage supports multiple Roslyn compiler API versions simultaneously (4.8, 4.11, and 4.14) through SDK version detection, separate project files, and conditional compilation. For information about the overall build integration, see Build Integration.
AutoLoggerMessage maintains compatibility with both .NET 8 and .NET 9 SDK releases by shipping three parallel implementations of the source generator, each targeting a different Roslyn compiler API version. This approach addresses breaking changes in the Roslyn API surface between compiler releases while ensuring users can adopt the generator regardless of their SDK version. This document covers:
SDK Version Mapping
| Roslyn Version | SDK Version Requirement | Primary .NET Target |
|---|---|---|
| 4.8 | < 8.0.402 | .NET 8.0 (early releases) |
| 4.11 | >= 8.0.402 and < 9.0 | .NET 8.0 (late releases) |
| 4.14 | >= 9.0 | .NET 9.0 |
The Roslyn compiler API introduces breaking changes between major versions, requiring separate implementations. The generator detects the SDK version at build time and references the appropriate project.
Sources: src/AutoLoggerMessageGenerator/AutoLoggerMessageGenerator.Build.targets1-67 tests/AutoLoggerMessageGenerator.IntegrationTests/AutoLoggerMessageGenerator.IntegrationTests.csproj8-18
The source generator implementation is split across three separate project files, all sharing the same source code but targeting different Roslyn API versions:
Each project file:
AutoLoggerMessageGenerator.Build.targets file for shared configurationMicrosoft.CodeAnalysis.CSharp via the $(RoslynApiVersion) propertynetstandard2.0 (required for Visual Studio compatibility)AutoLoggerMessageGeneratorThe projects are named:
AutoLoggerMessageGenerator.Roslyn4_8.csprojAutoLoggerMessageGenerator.Roslyn4_11.csprojAutoLoggerMessageGenerator.Roslyn4_14.csprojSources: src/AutoLoggerMessageGenerator/AutoLoggerMessageGenerator.Build.targets1-11
SDK version detection occurs using MSBuild's version comparison functions in project files:
The detection logic in integration tests demonstrates the pattern:
The $(RoslynVersion) property is then used to dynamically reference the correct project:
Sources: