From be2840af3933f877f9aa411addcb45dbf738f349 Mon Sep 17 00:00:00 2001
From: kasperk81 <83082615+kasperk81@users.noreply.github.com>
Date: Thu, 7 Nov 2024 02:09:59 +0200
Subject: [PATCH 1/5] Make MaxSupportedLangVersion calculation dynamic
Uses historical trend to calculate language version based on the
.NET version, removing hardcoded mappings. Ensures
future .NET versions automatically align with expected C# version.
---
.../MSBuildTask/Microsoft.CSharp.Core.targets | 29 ++++++-------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets b/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
index ad407778bafb0..8810b43f2482e 100644
--- a/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
+++ b/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
@@ -7,31 +7,20 @@
<_MaxSupportedLangVersion Condition="('$(TargetFrameworkIdentifier)' != '.NETCoreApp' OR '$(_TargetFrameworkVersionWithoutV)' < '3.0') AND
('$(TargetFrameworkIdentifier)' != '.NETStandard' OR '$(_TargetFrameworkVersionWithoutV)' < '2.1')">7.3
-
+
<_MaxSupportedLangVersion Condition="(('$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' < '5.0') OR
('$(TargetFrameworkIdentifier)' == '.NETStandard' AND '$(_TargetFrameworkVersionWithoutV)' == '2.1')) AND
'$(_MaxSupportedLangVersion)' == ''">8.0
-
- <_MaxSupportedLangVersion Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' == '5.0' AND
- '$(_MaxSupportedLangVersion)' == ''">9.0
-
-
- <_MaxSupportedLangVersion Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' == '6.0' AND
- '$(_MaxSupportedLangVersion)' == ''">10.0
-
-
- <_MaxSupportedLangVersion Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' == '7.0' AND
- '$(_MaxSupportedLangVersion)' == ''">11.0
-
-
- <_MaxSupportedLangVersion Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' == '8.0' AND
- '$(_MaxSupportedLangVersion)' == ''">12.0
-
-
- <_MaxSupportedLangVersion Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' == '9.0' AND
- '$(_MaxSupportedLangVersion)' == ''">13.0
+
+ <_MaxSupportedLangVersion Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND
+ '$(_MaxSupportedLangVersion)' == ''">$([MSBuild]::Add(9, $([MSBuild]::Subtract($(_TargetFrameworkVersionWithoutV), 5)))).0
$(_MaxSupportedLangVersion)
$(_MaxSupportedLangVersion)
From be16bc09ccff9a46a38c52c94a4db81eb278af31 Mon Sep 17 00:00:00 2001
From: kasperk81 <83082615+kasperk81@users.noreply.github.com>
Date: Thu, 7 Nov 2024 16:52:23 +0200
Subject: [PATCH 2/5] Update TargetTests.cs
---
src/Compilers/Core/MSBuildTaskTests/TargetTests.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Compilers/Core/MSBuildTaskTests/TargetTests.cs b/src/Compilers/Core/MSBuildTaskTests/TargetTests.cs
index fcc0626771d81..bcb6583df8dec 100644
--- a/src/Compilers/Core/MSBuildTaskTests/TargetTests.cs
+++ b/src/Compilers/Core/MSBuildTaskTests/TargetTests.cs
@@ -403,7 +403,7 @@ public void GenerateEditorConfigCoreHandlesMalformedCompilerVisibleItemMetadata(
[InlineData(".NETCoreApp", "7.0", "11.0")]
[InlineData(".NETCoreApp", "8.0", "12.0")]
[InlineData(".NETCoreApp", "9.0", "13.0")]
- [InlineData(".NETCoreApp", "10.0", "")]
+ [InlineData(".NETCoreApp", "10.0", "14.0")]
[InlineData(".NETStandard", "1.0", "7.3")]
[InlineData(".NETStandard", "1.5", "7.3")]
From 3a088afde9307ffcc15f8270e1c9bcd024b6bb55 Mon Sep 17 00:00:00 2001
From: kasperk81 <83082615+kasperk81@users.noreply.github.com>
Date: Thu, 7 Nov 2024 18:11:32 +0000
Subject: [PATCH 3/5] cap to max available version
---
src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets | 5 +++++
src/Compilers/Core/MSBuildTaskTests/TargetTests.cs | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets b/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
index 8810b43f2482e..bfbeca39bbe94 100644
--- a/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
+++ b/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
@@ -22,6 +22,11 @@
<_MaxSupportedLangVersion Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND
'$(_MaxSupportedLangVersion)' == ''">$([MSBuild]::Add(9, $([MSBuild]::Subtract($(_TargetFrameworkVersionWithoutV), 5)))).0
+
+ <_MaxAvailableLangVersion>13.0
+ <_MaxSupportedLangVersion Condition="Condition="'$(_MaxSupportedLangVersion)' != '' AND
+ '$(_MaxSupportedLangVersion)' > '$(_MaxAvailableLangVersion)'">$(_MaxAvailableLangVersion)
+
$(_MaxSupportedLangVersion)
$(_MaxSupportedLangVersion)
diff --git a/src/Compilers/Core/MSBuildTaskTests/TargetTests.cs b/src/Compilers/Core/MSBuildTaskTests/TargetTests.cs
index bcb6583df8dec..45c1d1a755fb3 100644
--- a/src/Compilers/Core/MSBuildTaskTests/TargetTests.cs
+++ b/src/Compilers/Core/MSBuildTaskTests/TargetTests.cs
@@ -403,7 +403,7 @@ public void GenerateEditorConfigCoreHandlesMalformedCompilerVisibleItemMetadata(
[InlineData(".NETCoreApp", "7.0", "11.0")]
[InlineData(".NETCoreApp", "8.0", "12.0")]
[InlineData(".NETCoreApp", "9.0", "13.0")]
- [InlineData(".NETCoreApp", "10.0", "14.0")]
+ [InlineData(".NETCoreApp", "10.0", "13.0")] // update when 14.0 is released
[InlineData(".NETStandard", "1.0", "7.3")]
[InlineData(".NETStandard", "1.5", "7.3")]
From 7c63e3c2cc577099714e2bc19f74085dfe5d852d Mon Sep 17 00:00:00 2001
From: kasperk81 <83082615+kasperk81@users.noreply.github.com>
Date: Thu, 7 Nov 2024 21:06:12 +0200
Subject: [PATCH 4/5] syntax
---
src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets b/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
index bfbeca39bbe94..f11e8b1adcf90 100644
--- a/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
+++ b/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
@@ -24,8 +24,8 @@
<_MaxAvailableLangVersion>13.0
- <_MaxSupportedLangVersion Condition="Condition="'$(_MaxSupportedLangVersion)' != '' AND
- '$(_MaxSupportedLangVersion)' > '$(_MaxAvailableLangVersion)'">$(_MaxAvailableLangVersion)
+ <_MaxSupportedLangVersion Condition="'$(_MaxSupportedLangVersion)' != '' AND
+ '$(_MaxSupportedLangVersion)' > '$(_MaxAvailableLangVersion)'">$(_MaxAvailableLangVersion)
$(_MaxSupportedLangVersion)
$(_MaxSupportedLangVersion)
From 510f13fea8b5496931cc2b4b9ac5fe008fec2f68 Mon Sep 17 00:00:00 2001
From: kasperk81 <83082615+kasperk81@users.noreply.github.com>
Date: Thu, 21 Nov 2024 21:50:28 +0200
Subject: [PATCH 5/5] Update CommandLineTests.cs
---
src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
index b6cf51975aba5..8acde11e175f7 100644
--- a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
+++ b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
@@ -1727,7 +1727,7 @@ public void LanguageVersionAdded_Canary()
// When a new version is added, this test will break. This list must be checked:
// - update the "UpgradeProject" codefixer
// - update all the tests that call this canary
- // - update MaxSupportedLangVersion (a relevant test should break when new version is introduced)
+ // - update _MaxAvailableLangVersion (a relevant test should break when new version is introduced)
// - email release management to add to the release notes (see old example: https://github.com/dotnet/core/pull/1454)
AssertEx.SetEqual(new[] { "default", "1", "2", "3", "4", "5", "6", "7.0", "7.1", "7.2", "7.3", "8.0", "9.0", "10.0", "11.0", "12.0", "13.0", "latest", "latestmajor", "preview" },
Enum.GetValues(typeof(LanguageVersion)).Cast().Select(v => v.ToDisplayString()));