Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:breaking-change: bump version to 5.0 and drop support for .NET Standard 2 and < .NET 6 #547

Merged
merged 2 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Run build script
id: build_script
run: ./build.ps1 -ci
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Setup .NET 6
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
dotnet-version: |
6.0.x
8.0.x
- name: Run docs generation
run: ./docs/generate.ps1

Expand Down
8 changes: 1 addition & 7 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

<PropertyGroup>
<WarningsNotAsErrors>$(WarningsNotAsErrors);1591</WarningsNotAsErrors>
<LangVersion>9.0</LangVersion>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<Nullable>enable</Nullable>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)src\StrongName.snk</AssemblyOriginatorKeyFile>
Expand All @@ -41,7 +40,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>4.1.1</VersionPrefix>
<VersionPrefix>5.0.0</VersionPrefix>
<VersionSuffix>beta</VersionSuffix>
<IncludePreReleaseLabelInPackageVersion Condition="'$(IS_STABLE_BUILD)' != 'true'">true</IncludePreReleaseLabelInPackageVersion>
<BuildNumber Condition=" '$(BuildNumber)' == '' ">$(GITHUB_RUN_NUMBER)</BuildNumber>
Expand All @@ -53,11 +52,6 @@
<InformationalVersion Condition="'$(RepositoryCommit)' != ''">$(PackageVersion)+$(RepositoryCommit)</InformationalVersion>
</PropertyGroup>

<ItemGroup>
<!-- For x-plat development -->
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="All" />
</ItemGroup>

<Import Project="$(MSBuildProjectDirectory)/releasenotes.props"
Condition="Exists('$(MSBuildProjectDirectory)/releasenotes.props')" />

Expand Down
2 changes: 1 addition & 1 deletion docs/generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ try {
if (-not (Test-Path $docfx)) {
mkdir -p $docfxRoot -ErrorAction Ignore | Out-Null
$temp = (New-TemporaryFile).FullName + ".zip"
Invoke-WebRequest "https://www.nuget.org/api/v2/package/docfx.console/$docfxVersion" -O $temp
Invoke-WebRequest "https://www.nuget.org/api/v2/package/docfx.console/$docfxVersion" -OutFile $temp
Expand-Archive $temp -DestinationPath $docfxRoot
Remove-Item $temp
if ($Install) {
Expand Down
2 changes: 1 addition & 1 deletion docs/samples/attributes/Attributes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion docs/samples/custom-attribute/CustomAttribute.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion docs/samples/custom-conventions/CustomConvention.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion docs/samples/generic-host/BuilderApi/BuilderApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion docs/samples/interactive-prompts/Prompt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion docs/samples/pager/Pager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions docs/samples/validation/attributes/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using System.ComponentModel.DataAnnotations;
using System.Linq;
using McMaster.Extensions.CommandLineUtils;
// This is required since .NET 8 introduced a new type System.ComponentModel.DataAnnotations.AllowedValuesAttribute
// which conflicts with the attribute in this library (added long before .NET 8.)
using AllowedValues = McMaster.Extensions.CommandLineUtils.AllowedValuesAttribute;

[MaxSizeOptionRequiresAttachmentValidation()]
class AttributeProgram
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/CommandLineUtils/Abstractions/CommandLineContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace McMaster.Extensions.CommandLineUtils.Abstractions
/// </summary>
public abstract class CommandLineContext
{
private string[] _args = new string[0];
private string[] _args = Array.Empty<string>();
private string _workDir = Directory.GetCurrentDirectory();
private IConsole _console = PhysicalConsole.Singleton;

Expand Down
8 changes: 8 additions & 0 deletions src/CommandLineUtils/Abstractions/ValueParserProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ private static readonly MethodInfo s_getParserGeneric
public IValueParser GetParser(Type type)
{
var method = s_getParserGeneric.MakeGenericMethod(type);
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
#pragma warning disable CS8603 // Possible null reference return.
return (IValueParser)method.Invoke(this, Array.Empty<object>());
#pragma warning restore CS8603 // Possible null reference return.
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
}

/// <summary>
Expand Down Expand Up @@ -121,8 +125,12 @@ public IValueParser GetParser(Type type)
{
return null;
}
#pragma warning disable CS8602 // Dereference of a possibly null reference.
var method = typeof(ValueTupleValueParser).GetMethod(nameof(ValueTupleValueParser.Create)).MakeGenericMethod(type.GenericTypeArguments[1]);
#pragma warning restore CS8602 // Dereference of a possibly null reference.
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
return (IValueParser)method.Invoke(null, new object[] { innerParser });
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public AllowedValuesAttribute(params string[] allowedValues)
public AllowedValuesAttribute(StringComparison comparer, params string[] allowedValues)
: base(GetDefaultError(allowedValues))
{
_allowedValues = allowedValues ?? new string[0];
_allowedValues = allowedValues ?? Array.Empty<string>();
Comparer = comparer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ internal CommandOption Configure(CommandLineApplication app, Type type, Func<obj

shortFormGetter = () =>
{
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
#pragma warning disable CS8603 // Possible null reference return.
return (string)methods[0].Invoke(targetInstanceFactory.Invoke(), Array.Empty<object>());
#pragma warning restore CS8603 // Possible null reference return.
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/CommandLineUtils/CommandArgument{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public CommandArgument(IValueParser<T> valueParser)
/// <summary>
/// The parsed value.
/// </summary>
#pragma warning disable CS8603 // Possible null reference return.
public T ParsedValue => ParsedValues.FirstOrDefault();
#pragma warning restore CS8603 // Possible null reference return.

/// <summary>
/// All parsed values;
Expand Down
6 changes: 6 additions & 0 deletions src/CommandLineUtils/CommandLineApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -877,13 +877,17 @@ void cancelHandler(object o, ConsoleCancelEventArgs e)

try
{
#pragma warning disable CS8622 // Nullability of reference types in type of parameter doesn't match the target delegate (possibly because of nullability attributes).
_context.Console.CancelKeyPress += cancelHandler;
#pragma warning restore CS8622 // Nullability of reference types in type of parameter doesn't match the target delegate (possibly because of nullability attributes).

return await command._handler(handlerCancellationTokenSource.Token);
}
finally
{
#pragma warning disable CS8622 // Nullability of reference types in type of parameter doesn't match the target delegate (possibly because of nullability attributes).
_context.Console.CancelKeyPress -= cancelHandler;
#pragma warning restore CS8622 // Nullability of reference types in type of parameter doesn't match the target delegate (possibly because of nullability attributes).
}
}

Expand Down Expand Up @@ -1146,7 +1150,9 @@ public virtual void Dispose()

internal IServiceProvider? AdditionalServices { get; set; }

#pragma warning disable CS8603 // Possible null reference return.
object IServiceProvider.GetService(Type serviceType) => _services.Value.GetService(serviceType);
#pragma warning restore CS8603 // Possible null reference return.

private sealed class ServiceProvider : IServiceProvider
{
Expand Down
2 changes: 2 additions & 0 deletions src/CommandLineUtils/CommandLineApplicationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ public static CommandOption VersionOptionFromAssemblyAttributes(this CommandLine
var infoVersion = assembly
?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion;
#pragma warning disable CS8602 // Dereference of a possibly null reference.
return string.IsNullOrWhiteSpace(infoVersion)
? assembly?.GetName().Version.ToString()
: infoVersion;
#pragma warning restore CS8602 // Dereference of a possibly null reference.
}
}
}
2 changes: 2 additions & 0 deletions src/CommandLineUtils/CommandOption{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public CommandOption(IValueParser<T> valueParser, string template, CommandOption
/// <summary>
/// The parsed value.
/// </summary>
#pragma warning disable CS8603 // Possible null reference return.
public T ParsedValue => ParsedValues.FirstOrDefault();
#pragma warning restore CS8603 // Possible null reference return.

/// <summary>
/// All parsed values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private void AddArgument(PropertyInfo prop,
if (r.SelectedCommand is IModelAccessor cmd)
{
var model = cmd.GetModel();
#pragma warning disable CS8602 // Dereference of a possibly null reference.
if (prop.DeclaringType.IsAssignableFrom(model.GetType()))
{
if (argument.Values.Count == 0)
Expand All @@ -175,6 +176,7 @@ private void AddArgument(PropertyInfo prop,
convention.Application.ValueParsers.ParseCulture));
}
}
#pragma warning restore CS8602 // Dereference of a possibly null reference.
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ private void ApplyImpl<TModel>(ConventionContext context)
goto nextCtor;
}

#pragma warning disable CS8604 // Possible null reference argument.
return () =>
throw new InvalidOperationException(
Strings.NoParameterTypeRegistered(ctorCandidate.DeclaringType, paramType));
#pragma warning restore CS8604 // Possible null reference argument.
}

args[i] = service;
Expand Down
Loading
Loading