Skip to content

Commit dd4d598

Browse files
Lower analyzer Roslyn reference to 4.8.0 for .NET 8+ SDK compat
The analyzer and code fix projects were referencing Microsoft.CodeAnalysis 5.3.0 (via central package management), which only loads in .NET 10+ SDK compilers. Users on .NET 8 or 9 SDKs would get CS9057 and the analyzer would silently not run. - Add VersionOverride="4.8.0" to Microsoft.CodeAnalysis.CSharp in the analyzer project and Microsoft.CodeAnalysis.CSharp.Workspaces in the code fixes project. Test projects keep 5.3.0 via central versioning. - Install .NET 8/9 runtimes in CI so multi-targeted tests can run. - Add analyzer-compat CI job that packs the built analyzer, installs it into a throwaway console project under .NET 8 and .NET 9 SDKs, and verifies no CS9057 warning is emitted. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4e1005e commit dd4d598

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

.github/workflows/dotnetBuild.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
uses: actions/setup-dotnet@v5
3636
with:
3737
global-json-file: "./global.json"
38+
dotnet-version: |
39+
8.x
40+
9.x
3841
3942
- name: Restore dependencies
4043
run: dotnet restore
@@ -52,3 +55,48 @@ jobs:
5255
trx-file-path: './TestResults/*.trx'
5356
test-outcomes: 'Failed'
5457
artifact-name: 'failed-tests-playlist'
58+
59+
- name: Pack Analyzer
60+
run: dotnet pack IntelliTect.Analyzer/IntelliTect.Analyzer/IntelliTect.Analyzer.csproj --configuration Release --no-build --output ./nupkg
61+
62+
- name: Upload NuGet Package
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: analyzer-nupkg
66+
path: ./nupkg/*.nupkg
67+
68+
analyzer-compat:
69+
name: Analyzer SDK Compat (${{ matrix.sdk }})
70+
runs-on: ubuntu-latest
71+
needs: build-and-test
72+
strategy:
73+
matrix:
74+
sdk: ['8.0.x', '9.0.x']
75+
steps:
76+
- name: Setup .NET ${{ matrix.sdk }}
77+
uses: actions/setup-dotnet@v5
78+
with:
79+
dotnet-version: ${{ matrix.sdk }}
80+
81+
- name: Download NuGet Package
82+
uses: actions/download-artifact@v4
83+
with:
84+
name: analyzer-nupkg
85+
path: ./nupkg
86+
87+
- name: Verify analyzer loads without CS9057
88+
run: |
89+
mkdir test-project && cd test-project
90+
dotnet new console
91+
# Add local package source and install the just-built analyzer
92+
dotnet nuget add source (Resolve-Path ../nupkg) --name local
93+
$pkg = Get-ChildItem ../nupkg/*.nupkg | Select-Object -First 1
94+
$version = [regex]::Match($pkg.Name, '(\d+\.\d+\.\d+.*)\.nupkg$').Groups[1].Value
95+
dotnet add package IntelliTect.Analyzers --version $version --source local
96+
# Build and check for CS9057 (analyzer references newer compiler than SDK provides)
97+
$output = dotnet build 2>&1
98+
$output | Write-Output
99+
if ($output -match 'CS9057') {
100+
Write-Error "CS9057 detected: Analyzer references a Roslyn version newer than this SDK supports"
101+
exit 1
102+
}

IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/IntelliTect.Analyzer.CodeFixes.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<ItemGroup>
1414
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
15-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="all" />
15+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="all" VersionOverride="4.8.0" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

IntelliTect.Analyzer/IntelliTect.Analyzer/IntelliTect.Analyzer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<ItemGroup>
2525
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
26-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
26+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" VersionOverride="4.8.0" />
2727
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers">
2828
<PrivateAssets>all</PrivateAssets>
2929
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

0 commit comments

Comments
 (0)