8000 Improve <LangVersion> selection (#3240) · dotnet/SqlClient@2772a8c · GitHub
[go: up one dir, main page]

Skip to content

Commit 2772a8c

Browse files
authored
Improve <LangVersion> selection (#3240)
* User Story 33639: Remove <LangVersion> from build config - Testing conditional <LangVersion> for .NET Framework only. * User Story 33639: Remove <LangVersion> from build config - Now choosing the natrual C# language version for .NET versions. - Explictily setting C# 13 for non-.NET targets (Framework, Standard, etc).
1 parent 41a5358 commit 2772a8c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/Directory.Build.props

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<LangVersion>9.0</LangVersion>
54
<TargetsWindows Condition="'$(OS)' == 'Windows_NT' AND '$(OSGroup)' == ''">true</TargetsWindows>
65
<TargetsWindows Condition="'$(OS)' != 'Windows_NT' AND '$(OSGroup)' == ''">false</TargetsWindows>
76
<TargetsWindows Condition="'$(OSGroup)' == 'Windows_NT'">true</TargetsWindows>
@@ -113,4 +112,25 @@
113112
<PropertyGroup>
114113
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>
115114
</PropertyGroup>
115+
116+
<!--
117+
For non-.NET, we explicitly set the C# language version to 13. This matches
118+
the language version used by the .NET 9 SDK, and provides helpful modern
119+
language features. While this isn't strictly supported by .NET in general,
120+
it works well in practice. There are very few C# language features that
121+
depend on SDK APIs, and we avoid them.
122+
123+
For .NET, we omit this property entirely, which results in the SDK choosing
124+
the C# language version that matches the .NET version.
125+
126+
Details here:
127+
128+
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-versioning
129+
130+
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version
131+
-->
132+
<PropertyGroup
133+
Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))' != '.NETCoreApp'">
134+
<LangVersion>13.0</LangVersion>
135+
</PropertyGroup>
116136
</Project>

0 commit comments

Comments
 (0)
0