Skip to content

Commit

Permalink
Update Microsoft.CSharp.Core.targets
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperk81 authored Nov 7, 2024
1 parent fb76caf commit e1c42a1
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,13 @@
'$(_MaxSupportedLangVersion)' == ''">8.0</_MaxSupportedLangVersion>

<!--
Set the base language version for .NET 5.0.
Based on the empirical pattern, each major .NET version release supports
a new language version. For example:
- .NET 5.0 -> C# 9.0
- .NET 6.0 -> C# 10.0
- .NET 7.0 -> C# 11.0
- .NET 8.0 -> C# 12.0
This pattern suggests a consistent, incremental increase in supported language versions.
Starting at 9 for .NET 5.0, we can compute the language version automatically for future versions.
-->
<_BaseLangVersion>9</_BaseLangVersion>

<!--
Calculate the maximum supported language version based on the Target Framework version.
- Extracts the major .NET version from $(TargetFrameworkVersion) (e.g., 5 for .NET 5.0, 6 for .NET 6.0).
- Finds the difference between the target .NET version and 5 (our base version).
- Adds this difference to the base language version (9) to dynamically determine the correct language version.
This approach follows the observed pattern and ensures scalability for future versions.
Automatically calculate the maximum supported C# language version based on the .NET Target Framework.
- Pattern: .NET 5.0 uses C# 9.0, .NET 6.0 uses C# 10.0, and so on.
- Starting from C# 9.0 for .NET 5.0, we add the difference between the major .NET version and 5
to determine the correct language version.
-->
<_MaxSupportedLangVersion Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_MaxSupportedLangVersion)' == ''">
$([MSBuild]::Add($(_BaseLangVersion), $([MSBuild]::Subtract($(_TargetFrameworkVersionWithoutV)), 5))))
$([MSBuild]::Add(9, $([MSBuild]::Subtract($(_TargetFrameworkVersionWithoutV), 5))))
</_MaxSupportedLangVersion>

<MaxSupportedLangVersion>$(_MaxSupportedLangVersion)</MaxSupportedLangVersion>
Expand Down

0 comments on commit e1c42a1

Please sign in to comment.