From 703e616404a30d1e6f3a49515d9729d3e720264a Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Fri, 23 Feb 2024 10:08:58 +0000 Subject: [PATCH 1/8] Use NetMinimum and NetFrameworkMinimum floating TFMs 1. By using NetMinimum and NetFrameworkMinimum as the TFM properties, the command-line-api repository will automatically target the minimum in-support version of .NET and .NET Framework. 2. Upgrade the TFM to net8.0 as net7.0 will soon be out-of-support and Tactics (leadership) asked repositories to move away from net7.0 already in the main branch. 3. Clean-up a few unnecessary msbuild properties and simplify items. 4. Clean-up the #if NETX compiler preprocessor directives. --- Directory.Build.props | 5 +-- Directory.Build.targets | 1 + System.CommandLine.v3.ncrunchsolution | 4 +-- samples/DragonFruit/DragonFruit.csproj | 2 +- .../HostingPlayground.csproj | 2 +- .../RenderingPlayground.csproj | 2 +- src/Common/ArgumentBuilder.cs | 2 +- src/Common/OptionBuilder.cs | 2 +- ....CommandLine.ApiCompatibility.Tests.csproj | 2 +- .../System.CommandLine.Benchmarks.csproj | 6 ++-- ...ystem.CommandLine.DragonFruit.Tests.csproj | 2 +- .../System.CommandLine.DragonFruit.csproj | 4 ++- .../System.CommandLine.DragonFruit.props | 2 ++ .../System.CommandLine.DragonFruit.targets | 2 ++ .../System.CommandLine.Generator.Tests.csproj | 2 +- .../System.CommandLine.Hosting.Tests.csproj | 3 +- .../System.CommandLine.Hosting.csproj | 6 +--- .../ModelBinderTests.cs | 2 +- ...ndLine.NamingConventionBinder.Tests.csproj | 3 +- ....CommandLine.NamingConventionBinder.csproj | 7 ++-- .../System.CommandLine.Rendering.Tests.csproj | 3 +- .../System.CommandLine.Rendering.csproj | 2 +- .../EndToEndTestApp/EndToEndTestApp.csproj | 10 +++--- .../dotnet-suggest.Tests.csproj | 2 +- src/System.CommandLine.Suggest/DotnetMuxer.cs | 2 +- .../dotnet-suggest.csproj | 2 +- .../Binding/TypeConversionTests.cs | 4 +-- .../CompilationTests.cs | 2 +- .../CompletionTests.cs | 8 ++--- .../System.CommandLine.Tests.csproj | 2 +- .../TestApps/NativeAOT/NativeAOT.csproj | 26 +++++++-------- .../TestApps/Trimming/Trimming.csproj | 32 +++++++++---------- src/System.CommandLine/ArgumentValidation.cs | 2 +- src/System.CommandLine/Argument{T}.cs | 2 +- .../ArgumentConverter.DefaultValues.cs | 4 +-- .../ArgumentConverter.StringConverters.cs | 4 +-- .../Binding/ArgumentConverter.cs | 2 +- src/System.CommandLine/ConsoleHelpers.cs | 2 +- .../Invocation/ProcessTerminationHandler.cs | 8 ++--- .../System.CommandLine.csproj | 8 ++--- .../DynamicallyAccessedMemberTypes.cs | 2 +- .../DynamicallyAccessedMembersAttribute.cs | 2 +- .../UnconditionalSuppressMessageAttribute.cs | 2 +- src/System.Diagnostics.CodeAnalysis.cs | 2 +- 44 files changed, 93 insertions(+), 103 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 62f3090979..3a3573c78e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -10,12 +10,13 @@ 10.0 + - $(NetCurrent) + $(NetCurrent) - net7.0 + net8.0 diff --git a/Directory.Build.targets b/Directory.Build.targets index 2ee9ff6e16..9618e6d02e 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -6,6 +6,7 @@ $(DefaultExcludesInProjectFolder);TestResults\** + false diff --git a/System.CommandLine.v3.ncrunchsolution b/System.CommandLine.v3.ncrunchsolution index 7d5820a216..f32e469597 100644 --- a/System.CommandLine.v3.ncrunchsolution +++ b/System.CommandLine.v3.ncrunchsolution @@ -2,8 +2,8 @@ True - TargetFrameworks = net7.0 - TargetFramework = net7.0 + TargetFrameworks = net8.0 + TargetFramework = net8.0 True diff --git a/samples/DragonFruit/DragonFruit.csproj b/samples/DragonFruit/DragonFruit.csproj index 7c72c4da2b..d3e7602473 100644 --- a/samples/DragonFruit/DragonFruit.csproj +++ b/samples/DragonFruit/DragonFruit.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + $(NetMinimum) true diff --git a/samples/HostingPlayground/HostingPlayground.csproj b/samples/HostingPlayground/HostingPlayground.csproj index 54bc18bb67..23bd95e28a 100644 --- a/samples/HostingPlayground/HostingPlayground.csproj +++ b/samples/HostingPlayground/HostingPlayground.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + $(NetMinimum) true $(NoWarn);CS1591 diff --git a/samples/RenderingPlayground/RenderingPlayground.csproj b/samples/RenderingPlayground/RenderingPlayground.csproj index 109f8622e1..9c49a13d37 100644 --- a/samples/RenderingPlayground/RenderingPlayground.csproj +++ b/samples/RenderingPlayground/RenderingPlayground.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + $(NetMinimum) true diff --git a/src/Common/ArgumentBuilder.cs b/src/Common/ArgumentBuilder.cs index 5d707e91ad..a233d29016 100644 --- a/src/Common/ArgumentBuilder.cs +++ b/src/Common/ArgumentBuilder.cs @@ -16,7 +16,7 @@ public static CliArgument CreateArgument(Type valueType, string name = "value") { var argumentType = typeof(CliArgument<>).MakeGenericType(valueType); -#if NET6_0_OR_GREATER +#if NET var ctor = (ConstructorInfo)argumentType.GetMemberWithSameMetadataDefinitionAs(_ctor); #else var ctor = argumentType.GetConstructor(new[] { typeof(string) }); diff --git a/src/Common/OptionBuilder.cs b/src/Common/OptionBuilder.cs index 768b3eddec..d5f0b40d33 100644 --- a/src/Common/OptionBuilder.cs +++ b/src/Common/OptionBuilder.cs @@ -18,7 +18,7 @@ internal static CliOption CreateOption(string name, Type valueType, string descr { var optionType = typeof(CliOption<>).MakeGenericType(valueType); -#if NET6_0_OR_GREATER +#if NET var ctor = (ConstructorInfo)optionType.GetMemberWithSameMetadataDefinitionAs(_ctor); #else var ctor = optionType.GetConstructor(new[] { typeof(string), typeof(string[]) }); diff --git a/src/System.CommandLine.ApiCompatibility.Tests/System.CommandLine.ApiCompatibility.Tests.csproj b/src/System.CommandLine.ApiCompatibility.Tests/System.CommandLine.ApiCompatibility.Tests.csproj index 670b1d0361..e35d58e30f 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/System.CommandLine.ApiCompatibility.Tests.csproj +++ b/src/System.CommandLine.ApiCompatibility.Tests/System.CommandLine.ApiCompatibility.Tests.csproj @@ -1,7 +1,7 @@ - $(TargetFrameworkForNETSDK) + $(NetMinimum) false diff --git a/src/System.CommandLine.Benchmarks/System.CommandLine.Benchmarks.csproj b/src/System.CommandLine.Benchmarks/System.CommandLine.Benchmarks.csproj index cf5e9701f6..4e313c53f6 100644 --- a/src/System.CommandLine.Benchmarks/System.CommandLine.Benchmarks.csproj +++ b/src/System.CommandLine.Benchmarks/System.CommandLine.Benchmarks.csproj @@ -1,6 +1,9 @@ + + $(NetMinimum) + Exe AnyCPU @@ -8,9 +11,6 @@ and automation failing to clean up the folders once the runs are over --> false - - $(TargetFrameworkForNETSDK) - False diff --git a/src/System.CommandLine.DragonFruit.Tests/System.CommandLine.DragonFruit.Tests.csproj b/src/System.CommandLine.DragonFruit.Tests/System.CommandLine.DragonFruit.Tests.csproj index e50606c1f9..5bf6a67097 100644 --- a/src/System.CommandLine.DragonFruit.Tests/System.CommandLine.DragonFruit.Tests.csproj +++ b/src/System.CommandLine.DragonFruit.Tests/System.CommandLine.DragonFruit.Tests.csproj @@ -1,7 +1,7 @@ - $(TargetFrameworkForNETSDK) + $(NetMinimum) AutoGeneratedProgram true diff --git a/src/System.CommandLine.DragonFruit/System.CommandLine.DragonFruit.csproj b/src/System.CommandLine.DragonFruit/System.CommandLine.DragonFruit.csproj index f3fc932610..a2a744ed67 100644 --- a/src/System.CommandLine.DragonFruit/System.CommandLine.DragonFruit.csproj +++ b/src/System.CommandLine.DragonFruit/System.CommandLine.DragonFruit.csproj @@ -1,7 +1,8 @@  + - true netstandard2.0 + true This package includes the experimental DragonFruit app model for System.CommandLine, which allows you to create a command line application using only a Main method while getting support for complex type binding, error reporting, help, shell completions, and more. @@ -17,4 +18,5 @@ + \ No newline at end of file diff --git a/src/System.CommandLine.DragonFruit/targets/System.CommandLine.DragonFruit.props b/src/System.CommandLine.DragonFruit/targets/System.CommandLine.DragonFruit.props index f0408287e8..59ac4bbc84 100644 --- a/src/System.CommandLine.DragonFruit/targets/System.CommandLine.DragonFruit.props +++ b/src/System.CommandLine.DragonFruit/targets/System.CommandLine.DragonFruit.props @@ -1,3 +1,4 @@ + @@ -7,4 +8,5 @@ true + diff --git a/src/System.CommandLine.DragonFruit/targets/System.CommandLine.DragonFruit.targets b/src/System.CommandLine.DragonFruit/targets/System.CommandLine.DragonFruit.targets index f3c5632a94..529b9a39f5 100644 --- a/src/System.CommandLine.DragonFruit/targets/System.CommandLine.DragonFruit.targets +++ b/src/System.CommandLine.DragonFruit/targets/System.CommandLine.DragonFruit.targets @@ -1,3 +1,4 @@ + @@ -78,4 +79,5 @@ + diff --git a/src/System.CommandLine.Generator.Tests/System.CommandLine.Generator.Tests.csproj b/src/System.CommandLine.Generator.Tests/System.CommandLine.Generator.Tests.csproj index 1afb0768e5..5642c088dc 100644 --- a/src/System.CommandLine.Generator.Tests/System.CommandLine.Generator.Tests.csproj +++ b/src/System.CommandLine.Generator.Tests/System.CommandLine.Generator.Tests.csproj @@ -1,7 +1,7 @@ - $(TargetFrameworkForNETSDK);net462 + $(NetMinimum);$(NetFrameworkMinimum) true true enable diff --git a/src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj b/src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj index b59dcc2f67..f76126c01d 100644 --- a/src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj +++ b/src/System.CommandLine.Hosting.Tests/System.CommandLine.Hosting.Tests.csproj @@ -1,8 +1,7 @@ - $(TargetFrameworkForNETSDK);net462 - false + $(NetMinimum);$(NetFrameworkMinimum) diff --git a/src/System.CommandLine.Hosting/System.CommandLine.Hosting.csproj b/src/System.CommandLine.Hosting/System.CommandLine.Hosting.csproj index a809c8cede..07d4a61bbc 100644 --- a/src/System.CommandLine.Hosting/System.CommandLine.Hosting.csproj +++ b/src/System.CommandLine.Hosting/System.CommandLine.Hosting.csproj @@ -1,15 +1,11 @@ + $(NetMinimum);netstandard2.1;netstandard2.0 true - netstandard2.0;netstandard2.1;$(TargetFrameworkForNETSDK) This package provides support for using System.CommandLine with Microsoft.Extensions.Hosting. - - portable - - true diff --git a/src/System.CommandLine.NamingConventionBinder.Tests/ModelBinderTests.cs b/src/System.CommandLine.NamingConventionBinder.Tests/ModelBinderTests.cs index f59a112d78..df7e5614a7 100644 --- a/src/System.CommandLine.NamingConventionBinder.Tests/ModelBinderTests.cs +++ b/src/System.CommandLine.NamingConventionBinder.Tests/ModelBinderTests.cs @@ -752,7 +752,7 @@ class DeployOptions public string BundleId { get; set; } } -#if NETCOREAPP2_1_OR_GREATER +#if NET [Theory] [InlineData("--class-with-span-ctor a51ca309-84fa-452f-96be-51e47702ffb4 --int-value 1234")] [InlineData("--class-with-span-ctor a51ca309-84fa-452f-96be-51e47702ffb4")] diff --git a/src/System.CommandLine.NamingConventionBinder.Tests/System.CommandLine.NamingConventionBinder.Tests.csproj b/src/System.CommandLine.NamingConventionBinder.Tests/System.CommandLine.NamingConventionBinder.Tests.csproj index fe999414c6..d4c911b4d8 100644 --- a/src/System.CommandLine.NamingConventionBinder.Tests/System.CommandLine.NamingConventionBinder.Tests.csproj +++ b/src/System.CommandLine.NamingConventionBinder.Tests/System.CommandLine.NamingConventionBinder.Tests.csproj @@ -1,8 +1,7 @@ - $(TargetFrameworkForNETSDK);net462 - 10 + $(NetMinimum);$(NetFrameworkMinimum) diff --git a/src/System.CommandLine.NamingConventionBinder/System.CommandLine.NamingConventionBinder.csproj b/src/System.CommandLine.NamingConventionBinder/System.CommandLine.NamingConventionBinder.csproj index 8d941fdabd..80d013a4c9 100644 --- a/src/System.CommandLine.NamingConventionBinder/System.CommandLine.NamingConventionBinder.csproj +++ b/src/System.CommandLine.NamingConventionBinder/System.CommandLine.NamingConventionBinder.csproj @@ -1,20 +1,17 @@  + $(NetMinimum);netstandard2.0 true System.CommandLine.NamingConventionBinder - $(TargetFrameworkForNETSDK);netstandard2.0 10 enable This package provides command handler support for System.CommandLine performs parameter and model binding by matching option and argument names to parameter and property names. true - - portable - - + diff --git a/src/System.CommandLine.Rendering.Tests/System.CommandLine.Rendering.Tests.csproj b/src/System.CommandLine.Rendering.Tests/System.CommandLine.Rendering.Tests.csproj index afc7fd89b2..d40676bada 100644 --- a/src/System.CommandLine.Rendering.Tests/System.CommandLine.Rendering.Tests.csproj +++ b/src/System.CommandLine.Rendering.Tests/System.CommandLine.Rendering.Tests.csproj @@ -1,8 +1,7 @@ - $(TargetFrameworkForNETSDK) - false + $(NetMinimum) diff --git a/src/System.CommandLine.Rendering/System.CommandLine.Rendering.csproj b/src/System.CommandLine.Rendering/System.CommandLine.Rendering.csproj index aeecd42acd..84da656bae 100644 --- a/src/System.CommandLine.Rendering/System.CommandLine.Rendering.csproj +++ b/src/System.CommandLine.Rendering/System.CommandLine.Rendering.csproj @@ -1,8 +1,8 @@ - true netstandard2.0 + true This package provides support for structured command line output rendering. Write code once that renders correctly in multiple output modes, including System.Console, virtual terminal (using ANSI escape sequences), and plain text. $(NoWarn);CS8632 diff --git a/src/System.CommandLine.Suggest.Tests/EndToEndTestApp/EndToEndTestApp.csproj b/src/System.CommandLine.Suggest.Tests/EndToEndTestApp/EndToEndTestApp.csproj index 76add0d5a9..540737328a 100644 --- a/src/System.CommandLine.Suggest.Tests/EndToEndTestApp/EndToEndTestApp.csproj +++ b/src/System.CommandLine.Suggest.Tests/EndToEndTestApp/EndToEndTestApp.csproj @@ -1,12 +1,12 @@ - - - - + $(NetMinimum) Exe - $(TargetFrameworkForNETSDK) + + + + diff --git a/src/System.CommandLine.Suggest.Tests/dotnet-suggest.Tests.csproj b/src/System.CommandLine.Suggest.Tests/dotnet-suggest.Tests.csproj index 76540b1a7a..d2cfb04d58 100644 --- a/src/System.CommandLine.Suggest.Tests/dotnet-suggest.Tests.csproj +++ b/src/System.CommandLine.Suggest.Tests/dotnet-suggest.Tests.csproj @@ -1,7 +1,7 @@ - $(TargetFrameworkForNETSDK) + $(NetMinimum) $(DefaultExcludesInProjectFolder);EndToEndTestApp\** diff --git a/src/System.CommandLine.Suggest/DotnetMuxer.cs b/src/System.CommandLine.Suggest/DotnetMuxer.cs index 92612e7044..961b6a6b83 100644 --- a/src/System.CommandLine.Suggest/DotnetMuxer.cs +++ b/src/System.CommandLine.Suggest/DotnetMuxer.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NET6_0_OR_GREATER +#if NET using System.IO; using System.Runtime.InteropServices; diff --git a/src/System.CommandLine.Suggest/dotnet-suggest.csproj b/src/System.CommandLine.Suggest/dotnet-suggest.csproj index 03bd30467a..b673ae01d0 100644 --- a/src/System.CommandLine.Suggest/dotnet-suggest.csproj +++ b/src/System.CommandLine.Suggest/dotnet-suggest.csproj @@ -1,8 +1,8 @@  + $(NetMinimum) Exe - $(TargetFrameworkForNETSDK) true true dotnet-suggest diff --git a/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs b/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs index 6f6a15a5ea..a9b62061df 100644 --- a/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs +++ b/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs @@ -623,7 +623,7 @@ public void Values_can_be_correctly_converted_to_ipaddress_when_custom_parser_is GetValue(option, "-us 1.2.3.4").Should().Be(IPAddress.Parse("1.2.3.4")); } -#if NETCOREAPP3_0_OR_GREATER +#if NET [Fact] public void Values_can_be_correctly_converted_to_ipendpoint_when_custom_parser_is_provided() { @@ -636,7 +636,7 @@ public void Values_can_be_correctly_converted_to_ipendpoint_when_custom_parser_i } #endif -#if NET6_0_OR_GREATER +#if NET [Fact] public void Values_can_be_correctly_converted_to_dateonly_without_the_parser_specifying_a_custom_converter() => GetValue(new CliOption("-us"), "-us 2022-03-02").Should().Be(DateOnly.Parse("2022-03-02")); diff --git a/src/System.CommandLine.Tests/CompilationTests.cs b/src/System.CommandLine.Tests/CompilationTests.cs index c2b43b708e..2c59c343c3 100644 --- a/src/System.CommandLine.Tests/CompilationTests.cs +++ b/src/System.CommandLine.Tests/CompilationTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NET6_0_OR_GREATER +#if NET using System.CommandLine.Suggest; using System.CommandLine.Tests.Utility; diff --git a/src/System.CommandLine.Tests/CompletionTests.cs b/src/System.CommandLine.Tests/CompletionTests.cs index 6e9b918051..67fe46d68f 100644 --- a/src/System.CommandLine.Tests/CompletionTests.cs +++ b/src/System.CommandLine.Tests/CompletionTests.cs @@ -782,12 +782,12 @@ public void When_parsing_from_text_if_the_proximate_option_is_completed_then_com { var command = new CliRootCommand { - CreateOptionWithAcceptOnlyFromAmong(name: "--framework", "net7.0"), + CreateOptionWithAcceptOnlyFromAmong(name: "--framework", "net8.0"), CreateOptionWithAcceptOnlyFromAmong(name: "--language", "C#"), new CliOption("--langVersion") }; var configuration = new CliConfiguration(command); - var completions = command.Parse("--framework net7.0 --l", configuration).GetCompletions(); + var completions = command.Parse("--framework net8.0 --l", configuration).GetCompletions(); completions.Select(item => item.Label) .Should() @@ -799,12 +799,12 @@ public void When_parsing_from_array_if_the_proximate_option_is_completed_then_co { var command = new CliRootCommand { - CreateOptionWithAcceptOnlyFromAmong(name: "--framework", "net7.0"), + CreateOptionWithAcceptOnlyFromAmong(name: "--framework", "net8.0"), CreateOptionWithAcceptOnlyFromAmong(name: "--language", "C#"), new CliOption("--langVersion") }; var configuration = new CliConfiguration(command); - var completions = command.Parse(new[]{"--framework","net7.0","--l"}, configuration).GetCompletions(); + var completions = command.Parse(new[]{"--framework","net8.0","--l"}, configuration).GetCompletions(); completions.Select(item => item.Label) .Should() diff --git a/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj b/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj index e282684919..1d1eaf0e45 100644 --- a/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj +++ b/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj @@ -1,7 +1,7 @@ - $(TargetFrameworkForNETSDK);net462 + $(NetMinimum);$(NetFrameworkMinimum) false $(DefaultExcludesInProjectFolder);TestApps\** diff --git a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj index 37f9b38667..e846eaf5cb 100644 --- a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj +++ b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj @@ -1,21 +1,19 @@ - - Exe - $(TargetFrameworkForNETSDK) - - false + + $(NetMinimum) + Exe + + false true - + - - ..\..\..\System.CommandLine\bin\Release\$(TargetFrameworkForNETSDK)\System.CommandLine.dll - + + ..\..\..\System.CommandLine\bin\$(Configuration)\$(TargetFramework)\System.CommandLine.dll + - - - $(SystemCommandLineDllPath) - - + + + diff --git a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj index 615b0764cf..7baf7b64cf 100644 --- a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj +++ b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj @@ -1,23 +1,21 @@ - - Exe - $(TargetFrameworkForNETSDK) - enable - enable - true - false - + + Exe + $(NetMinimum) + enable + enable + true + false + - - ..\..\..\System.CommandLine\bin\Release\$(TargetFrameworkForNETSDK)\System.CommandLine.dll - + + ..\..\..\System.CommandLine\bin\$(Configuration)\$(TargetFramework)\System.CommandLine.dll + - - - $(SystemCommandLineDllPath) - - - + + + + \ No newline at end of file diff --git a/src/System.CommandLine/ArgumentValidation.cs b/src/System.CommandLine/ArgumentValidation.cs index f5a418c5d8..11b2651858 100644 --- a/src/System.CommandLine/ArgumentValidation.cs +++ b/src/System.CommandLine/ArgumentValidation.cs @@ -82,7 +82,7 @@ private static void FileOrDirectoryExists(ArgumentResult result) if (checkFile && checkDirectory) { -#if NET7_0_OR_GREATER +#if NET if (!Path.Exists(token.Value)) #else if (!Directory.Exists(token.Value) && !File.Exists(token.Value)) diff --git a/src/System.CommandLine/Argument{T}.cs b/src/System.CommandLine/Argument{T}.cs index 8cf1981020..397a374304 100644 --- a/src/System.CommandLine/Argument{T}.cs +++ b/src/System.CommandLine/Argument{T}.cs @@ -169,7 +169,7 @@ public void AcceptLegalFileNamesOnly() { if (default(T) is null && typeof(T) != typeof(string)) { -#if NET7_0_OR_GREATER +#if NET if (typeof(T).IsSZArray) #else if (typeof(T).IsArray && typeof(T).GetArrayRank() == 1) diff --git a/src/System.CommandLine/Binding/ArgumentConverter.DefaultValues.cs b/src/System.CommandLine/Binding/ArgumentConverter.DefaultValues.cs index a44a8114d9..e19037b719 100644 --- a/src/System.CommandLine/Binding/ArgumentConverter.DefaultValues.cs +++ b/src/System.CommandLine/Binding/ArgumentConverter.DefaultValues.cs @@ -10,7 +10,7 @@ namespace System.CommandLine.Binding; internal static partial class ArgumentConverter { -#if NET6_0_OR_GREATER +#if NET private static ConstructorInfo? _listCtor; #endif @@ -20,7 +20,7 @@ private static Array CreateArray(Type itemType, int capacity) private static IList CreateEmptyList(Type listType) { -#if NET6_0_OR_GREATER +#if NET ConstructorInfo? listCtor = _listCtor; if (listCtor is null) diff --git a/src/System.CommandLine/Binding/ArgumentConverter.StringConverters.cs b/src/System.CommandLine/Binding/ArgumentConverter.StringConverters.cs index 4a48afbb34..7829f4f32b 100644 --- a/src/System.CommandLine/Binding/ArgumentConverter.StringConverters.cs +++ b/src/System.CommandLine/Binding/ArgumentConverter.StringConverters.cs @@ -27,7 +27,7 @@ private static Dictionary StringConverters return false; }, -#if NET6_0_OR_GREATER +#if NET [typeof(DateOnly)] = (string input, out object? value) => { if (DateOnly.TryParse(input, out var parsed)) @@ -195,7 +195,7 @@ private static Dictionary StringConverters return false; }, -#if NET6_0_OR_GREATER +#if NET [typeof(TimeOnly)] = (string input, out object? value) => { if (TimeOnly.TryParse(input, out var parsed)) diff --git a/src/System.CommandLine/Binding/ArgumentConverter.cs b/src/System.CommandLine/Binding/ArgumentConverter.cs index 9fa921348a..37d84e0aac 100644 --- a/src/System.CommandLine/Binding/ArgumentConverter.cs +++ b/src/System.CommandLine/Binding/ArgumentConverter.cs @@ -61,7 +61,7 @@ private static ArgumentConversionResult ConvertToken( if (type.IsEnum) { -#if NET7_0_OR_GREATER +#if NET if (Enum.TryParse(type, value, ignoreCase: true, out var converted)) { return Success(argumentResult, converted); diff --git a/src/System.CommandLine/ConsoleHelpers.cs b/src/System.CommandLine/ConsoleHelpers.cs index 2684413c89..46c91fb4e3 100644 --- a/src/System.CommandLine/ConsoleHelpers.cs +++ b/src/System.CommandLine/ConsoleHelpers.cs @@ -10,7 +10,7 @@ internal static class ConsoleHelpers private static readonly bool ColorsAreSupported = GetColorsAreSupported(); private static bool GetColorsAreSupported() -#if NET7_0_OR_GREATER +#if NET => !(OperatingSystem.IsBrowser() || OperatingSystem.IsAndroid() || OperatingSystem.IsIOS() || OperatingSystem.IsTvOS()) #else => !(RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")) diff --git a/src/System.CommandLine/Invocation/ProcessTerminationHandler.cs b/src/System.CommandLine/Invocation/ProcessTerminationHandler.cs index ead35b4eb0..4d273e5f4a 100644 --- a/src/System.CommandLine/Invocation/ProcessTerminationHandler.cs +++ b/src/System.CommandLine/Invocation/ProcessTerminationHandler.cs @@ -16,7 +16,7 @@ internal sealed class ProcessTerminationHandler : IDisposable private readonly CancellationTokenSource _handlerCancellationTokenSource; private readonly Task _startedHandler; private readonly TimeSpan _processTerminationTimeout; -#if NET7_0_OR_GREATER +#if NET private readonly IDisposable? _sigIntRegistration, _sigTermRegistration; #endif @@ -30,7 +30,7 @@ internal ProcessTerminationHandler( _startedHandler = startedHandler; _processTerminationTimeout = processTerminationTimeout; -#if NET7_0_OR_GREATER // we prefer the new API as they allow for cancelling SIGTERM +#if NET // we prefer the new API as they allow for cancelling SIGTERM if (!OperatingSystem.IsAndroid() && !OperatingSystem.IsIOS() && !OperatingSystem.IsTvOS() @@ -48,7 +48,7 @@ internal ProcessTerminationHandler( public void Dispose() { -#if NET7_0_OR_GREATER +#if NET if (_sigIntRegistration is not null) { _sigIntRegistration.Dispose(); @@ -61,7 +61,7 @@ public void Dispose() AppDomain.CurrentDomain.ProcessExit -= OnProcessExit; } -#if NET7_0_OR_GREATER +#if NET void OnPosixSignal(PosixSignalContext context) { context.Cancel = true; diff --git a/src/System.CommandLine/System.CommandLine.csproj b/src/System.CommandLine/System.CommandLine.csproj index 17a23bebad..31590c58ac 100644 --- a/src/System.CommandLine/System.CommandLine.csproj +++ b/src/System.CommandLine/System.CommandLine.csproj @@ -1,9 +1,9 @@ + $(NetMinimum);netstandard2.0 true System.CommandLine - $(TargetFrameworkForNETSDK);netstandard2.0 enable true latest @@ -11,16 +11,12 @@ true - + true true true - - portable - - diff --git a/src/System.CommandLine/System.Diagnostics.CodeAnalysis/DynamicallyAccessedMemberTypes.cs b/src/System.CommandLine/System.Diagnostics.CodeAnalysis/DynamicallyAccessedMemberTypes.cs index a139bdc050..ab74d4d079 100644 --- a/src/System.CommandLine/System.Diagnostics.CodeAnalysis/DynamicallyAccessedMemberTypes.cs +++ b/src/System.CommandLine/System.Diagnostics.CodeAnalysis/DynamicallyAccessedMemberTypes.cs @@ -1,6 +1,6 @@ // adapted from: https://github.com/dotnet/aspnetcore/blob/404d81767784552b0a148cb8c437332ebe726ae9/src/Shared/CodeAnalysis/DynamicallyAccessedMemberTypes.cs -#if !NET6_0_OR_GREATER +#if !NET // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. diff --git a/src/System.CommandLine/System.Diagnostics.CodeAnalysis/DynamicallyAccessedMembersAttribute.cs b/src/System.CommandLine/System.Diagnostics.CodeAnalysis/DynamicallyAccessedMembersAttribute.cs index a39283b0ab..509c9cdb51 100644 --- a/src/System.CommandLine/System.Diagnostics.CodeAnalysis/DynamicallyAccessedMembersAttribute.cs +++ b/src/System.CommandLine/System.Diagnostics.CodeAnalysis/DynamicallyAccessedMembersAttribute.cs @@ -1,6 +1,6 @@ // adapted from: https://github.com/dotnet/aspnetcore/blob/404d81767784552b0a148cb8c437332ebe726ae9/src/Shared/CodeAnalysis/DynamicallyAccessedMembersAttribute.cs#L29 -#if !NET6_0_OR_GREATER +#if !NET // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. diff --git a/src/System.CommandLine/System.Diagnostics.CodeAnalysis/UnconditionalSuppressMessageAttribute.cs b/src/System.CommandLine/System.Diagnostics.CodeAnalysis/UnconditionalSuppressMessageAttribute.cs index 8c54ed2c91..8a717eb5ad 100644 --- a/src/System.CommandLine/System.Diagnostics.CodeAnalysis/UnconditionalSuppressMessageAttribute.cs +++ b/src/System.CommandLine/System.Diagnostics.CodeAnalysis/UnconditionalSuppressMessageAttribute.cs @@ -1,6 +1,6 @@ // adapted from: https://github.com/dotnet/runtime/blob/a5159b1a8840632ad34cf59c5aaf77040cb6ceda/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/UnconditionalSuppressMessageAttribute.cs#L21 -#if !NET6_0_OR_GREATER +#if !NET // Licensed to the .NET Foundation under one or more agreements. diff --git a/src/System.Diagnostics.CodeAnalysis.cs b/src/System.Diagnostics.CodeAnalysis.cs index 8a5b242094..53a18265de 100644 --- a/src/System.Diagnostics.CodeAnalysis.cs +++ b/src/System.Diagnostics.CodeAnalysis.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#if !NET6_0_OR_GREATER +#if !NET #pragma warning disable CA1801, CA1822 From d40bebb9111747b9dc8ab67855d0c343df6cea53 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Fri, 23 Feb 2024 11:14:00 +0000 Subject: [PATCH 2/8] fixes --- Directory.Build.props | 10 +++------- src/System.CommandLine.Tests/CompilationTests.cs | 6 +----- .../TestApps/NativeAOT/NativeAOT.csproj | 6 +----- .../TestApps/Trimming/Trimming.csproj | 7 +++---- 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 3a3573c78e..df6391b8cb 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -8,15 +8,11 @@ $(NoWarn);NU5125;CS0618 MIT 10.0 - - - - - $(NetCurrent) - - net8.0 + net462 + + $(NetCurrent) diff --git a/src/System.CommandLine.Tests/CompilationTests.cs b/src/System.CommandLine.Tests/CompilationTests.cs index 2c59c343c3..873c00c54c 100644 --- a/src/System.CommandLine.Tests/CompilationTests.cs +++ b/src/System.CommandLine.Tests/CompilationTests.cs @@ -17,13 +17,10 @@ namespace System.CommandLine.Tests; public class CompilationTests { private readonly ITestOutputHelper _output; - private readonly string _systemCommandLineDllPath; public CompilationTests(ITestOutputHelper output) { _output = output; - - _systemCommandLineDllPath = typeof(CliCommand).Assembly.Location; } [ReleaseBuildOnlyTheory] @@ -57,9 +54,8 @@ private void PublishAndValidate(string appName, string warningText, string addit workingDirectory: workingDirectory); string publishCommand = string.Format( - "publish -c Release -r {0} --self-contained -p:SystemCommandLineDllPath=\"{1}\" -p:TreatWarningsAsErrors=true {2}", + "publish -c Release -r {0} --self-contained -p:TreatWarningsAsErrors=true {1}", rId, - _systemCommandLineDllPath, additionalArgs); var exitCode = Process.RunToCompletion( diff --git a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj index e846eaf5cb..753b06ff6c 100644 --- a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj +++ b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj @@ -8,12 +8,8 @@ true - - ..\..\..\System.CommandLine\bin\$(Configuration)\$(TargetFramework)\System.CommandLine.dll - - - + diff --git a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj index 7baf7b64cf..7098430bed 100644 --- a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj +++ b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj @@ -9,12 +9,11 @@ false - - ..\..\..\System.CommandLine\bin\$(Configuration)\$(TargetFramework)\System.CommandLine.dll - + + + - From 63290bf4cd7468941be8661e993a79a989a93b51 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Fri, 23 Feb 2024 12:36:00 +0000 Subject: [PATCH 3/8] more fixes --- .../TestApps/NativeAOT/NativeAOT.csproj | 2 +- src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj index 753b06ff6c..404a9c346b 100644 --- a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj +++ b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj index 7098430bed..bf639685c2 100644 --- a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj +++ b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj @@ -10,7 +10,7 @@ - + From 732fb582001304732ed5da95639f7bde130320bc Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Fri, 23 Feb 2024 12:55:00 +0000 Subject: [PATCH 4/8] Update dependencies --- Directory.Packages.props | 10 +++++----- samples/DragonFruit/DragonFruit.csproj | 2 +- samples/RenderingPlayground/RenderingPlayground.csproj | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index d47f016a18..8fd986560f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -14,16 +14,16 @@ - - - + + + - + - + diff --git a/samples/DragonFruit/DragonFruit.csproj b/samples/DragonFruit/DragonFruit.csproj index d3e7602473..ab9f75ed4c 100644 --- a/samples/DragonFruit/DragonFruit.csproj +++ b/samples/DragonFruit/DragonFruit.csproj @@ -1,8 +1,8 @@  - Exe $(NetMinimum) + Exe true diff --git a/samples/RenderingPlayground/RenderingPlayground.csproj b/samples/RenderingPlayground/RenderingPlayground.csproj index 9c49a13d37..6b95cadc76 100644 --- a/samples/RenderingPlayground/RenderingPlayground.csproj +++ b/samples/RenderingPlayground/RenderingPlayground.csproj @@ -1,8 +1,8 @@ - Exe $(NetMinimum) + Exe true From 11ce61a9cb90e65a33a4b2128d51fa5ec8780f38 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Sun, 25 Feb 2024 12:36:56 +0100 Subject: [PATCH 5/8] Update NativeAOT.csproj --- .../TestApps/NativeAOT/NativeAOT.csproj | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj index 404a9c346b..f428f7045e 100644 --- a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj +++ b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj @@ -3,13 +3,11 @@ $(NetMinimum) Exe - - false true - + From 2fc5c448bd0a1fa7c704c62b630f434535a8d964 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Sun, 25 Feb 2024 12:37:26 +0100 Subject: [PATCH 6/8] Update Trimming.csproj --- .../TestApps/Trimming/Trimming.csproj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj index bf639685c2..3712b043a0 100644 --- a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj +++ b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj @@ -6,15 +6,14 @@ enable enable true - false - + - \ No newline at end of file + From 1febb6039ceab2ac088b3ddadd10738fee5967ea Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Mon, 24 Jun 2024 12:56:39 +0000 Subject: [PATCH 7/8] Fix test and nit styling --- ...Tests.System_CommandLine_api_is_not_changed.approved.txt | 2 +- .../System.CommandLine.Tests.csproj | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt index c3e8c803f5..b2a228caa8 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt +++ b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt @@ -252,7 +252,7 @@ System.CommandLine.Parsing public System.Boolean Equals(CliToken other) public System.Int32 GetHashCode() public System.String ToString() - public enum CliTokenType : System.Enum, System.IComparable, System.IConvertible, System.IFormattable + public enum CliTokenType : System.Enum, System.IComparable, System.IConvertible, System.IFormattable, System.ISpanFormattable Argument=0 Command=1 Option=2 diff --git a/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj b/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj index 93c90fbf11..f70e8472d9 100644 --- a/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj +++ b/src/System.CommandLine.Tests/System.CommandLine.Tests.csproj @@ -5,12 +5,12 @@ false $(DefaultExcludesInProjectFolder);TestApps\** - + - + @@ -18,7 +18,7 @@ - + From 8d0a086a6b2abd71158cda20740174a8a37fcf38 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Mon, 24 Jun 2024 13:19:18 +0000 Subject: [PATCH 8/8] Fix tests --- Directory.Build.props | 3 +++ .../TestApps/NativeAOT/NativeAOT.csproj | 3 ++- src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index df6391b8cb..5883ab0920 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,8 +9,11 @@ MIT 10.0 + net8.0 net462 + net481 + $(NetCurrent) diff --git a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj index f428f7045e..3748b11a26 100644 --- a/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj +++ b/src/System.CommandLine.Tests/TestApps/NativeAOT/NativeAOT.csproj @@ -4,10 +4,11 @@ $(NetMinimum) Exe true + false - + diff --git a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj index 3712b043a0..4294cd1c4b 100644 --- a/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj +++ b/src/System.CommandLine.Tests/TestApps/Trimming/Trimming.csproj @@ -6,10 +6,11 @@ enable enable true + false - +