Fix runtime detection in targets file#477
Conversation
There was a problem hiding this comment.
Pull Request Overview
A fix to ensure the .targets file correctly detects installed .NET SDK versions by capturing and parsing the dotnet --list-sdks output.
- Enabled MSBuild capture of SDK list output (
StdOut) for detection - Consolidated version checks into a single
PropertyGroupwithIsMatchingXflags and conditional overrides - Removed legacy version-specific groups and the
FlatSharpPrettyPrintflag handling, and added a diagnostic message
Comments suppressed due to low confidence (2)
src/FlatSharp.Compiler/FlatSharp.Compiler.targets:174
- Removing the
FlatSharpPrettyPrintproperty group disables the--pretty-printoption for the compiler; reintroduce conditional handling or merge it into the unifiedCompilerCommandconstruction.
<PropertyGroup Condition=" '$(FlatSharpPrettyPrint)' == 'true' ">
src/FlatSharp.Compiler/FlatSharp.Compiler.targets:103
- [nitpick] Hard-coding version checks for each major release requires manual updates for .NET 10+; consider extracting the highest major version dynamically to reduce future maintenance.
<IsMatching6>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '6\\.0\\.\d+'))</IsMatching6>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #477 +/- ##
=======================================
Coverage 96.04% 96.04%
=======================================
Files 124 124
Lines 8928 8928
Branches 749 749
=======================================
Hits 8575 8575
Misses 261 261
Partials 92 92 Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR refactors how the FlatSharp compiler MSBuild targets detect the .NET version and cleans up CI workflow configurations.
- Switches from
dotnet --list-sdkstodotnet --versionfor version detection - Consolidates
CompilerVersionassignments into onePropertyGroupwith conditional overrides for .NET 6–9 - Removes the deprecated
dotnet-qualityinput from CI workflow files
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/FlatSharp.Compiler/FlatSharp.Compiler.targets | Updated runtime detection logic; refactored CompilerVersion settings; added a diagnostic message |
| .github/workflows/stryker.yml | Removed deprecated dotnet-quality input |
| .github/workflows/dotnet.yml | Removed deprecated dotnet-quality input |
| .github/workflows/codecov.yml | Removed deprecated dotnet-quality input |
Comments suppressed due to low confidence (1)
src/FlatSharp.Compiler/FlatSharp.Compiler.targets:107
- [nitpick] Setting
CompilerVersiontonet9.0by default makes the explicit condition for 9.0 redundant. You could remove the 9-case or adjust the default placement for clarity.
<CompilerVersion>net9.0</CompilerVersion>
| <Exec Command="dotnet --version" ConsoleToMsBuild="true"> | ||
| <Output TaskParameter="ConsoleOutput" PropertyName="StdOut" /> | ||
| </Exec> | ||
|
|
||
| <PropertyGroup> | ||
| <CompilerVersion>net9.0</CompilerVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- try .net6.0. --> | ||
| <PropertyGroup Condition=" $([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '6\.0\.\d+')) "> | ||
| <CompilerVersion>net6.0</CompilerVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- try .net7.0. --> | ||
| <PropertyGroup Condition=" $([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '7\.0\.\d+')) "> | ||
| <CompilerVersion>net7.0</CompilerVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- try .net8.0. --> | ||
| <PropertyGroup Condition=" $([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '8\.0\.\d+')) "> | ||
| <CompilerVersion>net8.0</CompilerVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- try .net9.0. --> | ||
| <PropertyGroup Condition=" $([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '9\.0\.\d+')) "> | ||
| <CompilerVersion>net9.0</CompilerVersion> | ||
| </PropertyGroup> | ||
| <IsMatching6>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '6\.0\.\d+'))</IsMatching6> | ||
| <IsMatching7>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '7\.0\.\d+'))</IsMatching7> | ||
| <IsMatching8>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '8\.0\.\d+'))</IsMatching8> | ||
| <IsMatching9>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '9\.0\.\d+'))</IsMatching9> |
There was a problem hiding this comment.
Using dotnet --version reports the SDK version, not installed runtimes. To detect runtimes, consider using dotnet --list-runtimes instead.
| <Exec Command="dotnet --version" ConsoleToMsBuild="true"> | |
| <Output TaskParameter="ConsoleOutput" PropertyName="StdOut" /> | |
| </Exec> | |
| <PropertyGroup> | |
| <CompilerVersion>net9.0</CompilerVersion> | |
| </PropertyGroup> | |
| <!-- try .net6.0. --> | |
| <PropertyGroup Condition=" $([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '6\.0\.\d+')) "> | |
| <CompilerVersion>net6.0</CompilerVersion> | |
| </PropertyGroup> | |
| <!-- try .net7.0. --> | |
| <PropertyGroup Condition=" $([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '7\.0\.\d+')) "> | |
| <CompilerVersion>net7.0</CompilerVersion> | |
| </PropertyGroup> | |
| <!-- try .net8.0. --> | |
| <PropertyGroup Condition=" $([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '8\.0\.\d+')) "> | |
| <CompilerVersion>net8.0</CompilerVersion> | |
| </PropertyGroup> | |
| <!-- try .net9.0. --> | |
| <PropertyGroup Condition=" $([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '9\.0\.\d+')) "> | |
| <CompilerVersion>net9.0</CompilerVersion> | |
| </PropertyGroup> | |
| <IsMatching6>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '6\.0\.\d+'))</IsMatching6> | |
| <IsMatching7>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '7\.0\.\d+'))</IsMatching7> | |
| <IsMatching8>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '8\.0\.\d+'))</IsMatching8> | |
| <IsMatching9>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), '9\.0\.\d+'))</IsMatching9> | |
| <Exec Command="dotnet --list-runtimes" ConsoleToMsBuild="true"> | |
| <Output TaskParameter="ConsoleOutput" PropertyName="StdOut" /> | |
| </Exec> | |
| <PropertyGroup> | |
| <IsMatching6>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), 'Microsoft\.NETCore\.App 6\.0\.\d+'))</IsMatching6> | |
| <IsMatching7>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), 'Microsoft\.NETCore\.App 7\.0\.\d+'))</IsMatching7> | |
| <IsMatching8>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), 'Microsoft\.NETCore\.App 8\.0\.\d+'))</IsMatching8> | |
| <IsMatching9>$([System.Text.RegularExpressions.Regex]::IsMatch($(StdOut), 'Microsoft\.NETCore\.App 9\.0\.\d+'))</IsMatching9> |
…om/jamescourtney/FlatSharp into fix_targets_file_runtime_detection
* Fix runtime detection in targets file * Restore pretty print * Use --version instead of --list-sdks * Update dotnet.yml * Update codecov.yml * Update stryker.yml * copilot can't make up its mind
Fix for #476