Skip to content

Commit c1cd06d

Browse files
authored
Standardize $(LangVersion) in netstandard2.0 projects (#1322)
The default `$(LangVersion)` for `netstandard2.0` projects is [C# 7.3][0], which does not contain many of the niceties we would like to use. Throughout our history we have updated individual projects to use the latest language features, but this has led to inconsistencies. Instead, standardize this in `Directory.Build.targets` to use a common C# language version for `netstandard2.0` projects. Note that we standardized on [C# 13.0][1] -- the default in .NET 9 -- instead of `latest`, as `latest` is discouraged because it can change based on what versions are installed on a machine. [0]: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-73 [1]: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-13
1 parent 9f48ecf commit c1cd06d

File tree

9 files changed

+5
-10
lines changed

9 files changed

+5
-10
lines changed

Directory.Build.targets

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
<DefineConstants>$(DefineConstants);INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
1111
</PropertyGroup>
1212

13+
<!-- Automatically support the latest C# for netstandard2.0 projects -->
14+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
15+
<LangVersion>13.0</LangVersion>
16+
</PropertyGroup>
17+
1318
<!-- Add Roslyn analyzers NuGet to all projects -->
1419
<ItemGroup Condition=" '$(DisableRoslynAnalyzers)' != 'True' ">
1520
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">

build-tools/Java.Interop.BootstrapTasks/Java.Interop.BootstrapTasks.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
6-
<LangVersion>11.0</LangVersion>
76
</PropertyGroup>
87

98
<Import Project="..\..\TargetFrameworkDependentValues.props" />

src/Java.Interop.Localization/Java.Interop.Localization.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>8.0</LangVersion>
65
<Nullable>enable</Nullable>
76
<NeutralLanguage>en</NeutralLanguage>
87
<SignAssembly>true</SignAssembly>

src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>8.0</LangVersion>
65
<Nullable>enable</Nullable>
76
<SignAssembly>true</SignAssembly>
87
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>

src/Java.Interop.Tools.Diagnostics/Java.Interop.Tools.Diagnostics.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>8.0</LangVersion>
65
<Nullable>enable</Nullable>
76
<SignAssembly>true</SignAssembly>
87
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>

src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>11.0</LangVersion>
65
<Nullable>enable</Nullable>
76
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
87
<SignAssembly>true</SignAssembly>

src/Java.Interop.Tools.JavaSource/Java.Interop.Tools.JavaSource.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>$(DotNetTargetFramework)</TargetFramework>
5-
<LangVersion>8.0</LangVersion>
65
<Nullable>enable</Nullable>
76
</PropertyGroup>
87

src/Java.Interop.Tools.Maven/Java.Interop.Tools.Maven.csproj

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>11.0</LangVersion>
6-
<Nullable>enable</Nullable>
75
<Nullable>enable</Nullable>
86
<SignAssembly>true</SignAssembly>
97
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>

src/Java.Interop/Java.Interop.csproj

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
<OutputPath>$(ToolOutputFullPath)</OutputPath>
2828
<DocumentationFile>$(ToolOutputFullPath)Java.Interop.xml</DocumentationFile>
2929
<JNIEnvGenPath>$(BuildToolOutputFullPath)</JNIEnvGenPath>
30-
<LangVersion Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">9.0</LangVersion>
31-
<LangVersion Condition=" '$(LangVersion)' == '' ">8.0</LangVersion>
3230
<Version>$(JICoreLibVersion)</Version>
3331
<Standalone Condition=" '$(Standalone)' == '' ">true</Standalone>
3432
</PropertyGroup>

0 commit comments

Comments
 (0)