Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 2ca07d2

Browse files
authored
Target .NET6 instead of .NET Standard 2.0 and .NET Core 3.1 (#280)
* Set Target Framework to net6.0, remove conditional compilations and fix variety of arising nullability errors * Fix typos * Use static where possible for private methods * Fix typo in internal class name * Improve style consistency in xml doc comments * Simplify control flow * Use Contains over IndexOf >= 0 * Modernize code style and adjust indentation for consistency * Use discard over __ * Remove redundant annotations
1 parent f31dbfa commit 2ca07d2

34 files changed

+59
-169
lines changed

src/Kestrel.Certificates/KestrelHttpsOptionsExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Microsoft.AspNetCore.Hosting;
99

1010
/// <summary>
11-
/// API for configuring Kestrel certificiate options
11+
/// API for configuring Kestrel certificate options
1212
/// </summary>
1313
public static class KestrelHttpsOptionsExtensions
1414
{
@@ -22,7 +22,7 @@ public static HttpsConnectionAdapterOptions UseServerCertificateSelector(
2222
this HttpsConnectionAdapterOptions httpsOptions,
2323
IServerCertificateSelector certificateSelector)
2424
{
25-
httpsOptions.ServerCertificateSelector = certificateSelector.Select;
25+
httpsOptions.ServerCertificateSelector = certificateSelector.Select!;
2626
return httpsOptions;
2727
}
2828
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
4+
<TargetFramework>net6.0</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
<Nullable>enable</Nullable>
77
<IsPackable>true</IsPackable>
@@ -13,12 +13,9 @@ This library includes API for dynamically selecting which HTTPS certificate to u
1313
<PackageVersion Condition="'$(IncludePreReleaseLabelInPackageVersion)' == 'true'">$(PackageVersion)-$(VersionSuffix)</PackageVersion>
1414
</PropertyGroup>
1515

16-
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
16+
<ItemGroup>
1717
<FrameworkReference Include="Microsoft.AspNetCore.App" />
1818
</ItemGroup>
1919

20-
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
21-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Core" Version="2.1.25" />
22-
</ItemGroup>
2320

2421
</Project>

src/LettuceEncrypt.Azure/AzureKeyVaultLettuceEncryptOptions.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Copyright (c) Nate McMaster.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
#if FEATURE_VALIDATE_DATA_ANNOTATIONS
54
using System.ComponentModel.DataAnnotations;
6-
#endif
75
using Azure.Core;
86
using Azure.Identity;
97
using LettuceEncrypt.Accounts;
@@ -18,10 +16,8 @@ public class AzureKeyVaultLettuceEncryptOptions
1816
/// <summary>
1917
/// Gets or sets the Url for the KeyVault instance.
2018
/// </summary>
21-
#if FEATURE_VALIDATE_DATA_ANNOTATIONS
2219
[Url]
2320
[Required]
24-
#endif
2521
public string AzureKeyVaultEndpoint { get; set; } = null!;
2622

2723
/// <summary>
@@ -34,8 +30,6 @@ public class AzureKeyVaultLettuceEncryptOptions
3430
/// This is a JSON string which encodes the information in <see cref="AccountModel"/>.
3531
/// If not set, the name defaults to the name of the "le-account-${ACME server hostname}".
3632
/// </summary>
37-
#if FEATURE_VALIDATE_DATA_ANNOTATIONS
3833
[MaxLength(127)]
39-
#endif
4034
public string? AccountKeySecretName { get; set; }
4135
}

src/LettuceEncrypt.Azure/AzureLettuceEncryptExtensions.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,10 @@ public static ILettuceEncryptServiceBuilder PersistCertificatesToAzureKeyVault(
5757
config?.Bind("LettuceEncrypt:AzureKeyVault", o));
5858
});
5959

60-
var options = services
60+
services
6161
.AddOptions<AzureKeyVaultLettuceEncryptOptions>()
62-
.Configure(configure);
63-
64-
#if FEATURE_VALIDATE_DATA_ANNOTATIONS
65-
options.ValidateDataAnnotations();
66-
#endif
62+
.Configure(configure)
63+
.ValidateDataAnnotations();
6764

6865
return builder;
6966
}

src/LettuceEncrypt.Azure/LettuceEncrypt.Azure.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
4+
<TargetFramework>net6.0</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
<Nullable>enable</Nullable>
77
<IsPackable>true</IsPackable>
@@ -12,10 +12,6 @@ See https://nuget.org/packages/LettuceEncrypt for more details.
1212
</PackageDescription>
1313
</PropertyGroup>
1414

15-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
16-
<DefineConstants>$(DefineConstants);FEATURE_VALIDATE_DATA_ANNOTATIONS</DefineConstants>
17-
</PropertyGroup>
18-
1915
<ItemGroup>
2016
<PackageReference Include="Azure.Identity" Version="1.6.0" />
2117
<PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.3.0" />

src/LettuceEncrypt/FileSystemPersistenceExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class FileSystemStorageExtensions
2222
/// </summary>
2323
/// <param name="builder"></param>
2424
/// <param name="directory">The root directory for storing information. Information may be stored in subdirectories.</param>
25-
/// <param name="pfxPassword">Set to null or empty for passwordless .pfx files.</param>
25+
/// <param name="pfxPassword">Set to null or empty for password-less .pfx files.</param>
2626
/// <returns></returns>
2727
public static ILettuceEncryptServiceBuilder PersistDataToDirectory(
2828
this ILettuceEncryptServiceBuilder builder,
@@ -47,7 +47,7 @@ public static ILettuceEncryptServiceBuilder PersistDataToDirectory(
4747

4848
foreach (var serviceDescriptor in otherFileSystemRepoServices)
4949
{
50-
var otherRepo = (FileSystemCertificateRepository)serviceDescriptor.ImplementationInstance;
50+
var otherRepo = (FileSystemCertificateRepository)serviceDescriptor.ImplementationInstance!;
5151
if (otherRepo.RootDir.Equals(directory))
5252
{
5353
if (otherRepo.PfxPassword != pfxPassword)

src/LettuceEncrypt/ICertificateRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface ICertificateRepository
1313
/// <summary>
1414
/// Save the certificate.
1515
/// </summary>
16-
/// <param name="certificate">The certificate, including its private keys</param>
16+
/// <param name="certificate">The certificate, including its private keys.</param>
1717
/// <param name="cancellationToken">A token which, when canceled, should stop any async operations.</param>
1818
/// <returns>A task which completes once the certificate is done saving.</returns>
1919
Task SaveAsync(X509Certificate2 certificate, CancellationToken cancellationToken);

src/LettuceEncrypt/ICertificateSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public interface ICertificateSource
1414
/// Gets available certificates from the source.
1515
/// </summary>
1616
/// <param name="cancellationToken">A cancellation token.</param>
17-
/// <returns>A collection of certificates</returns>
17+
/// <returns>A collection of certificates.</returns>
1818
Task<IEnumerable<X509Certificate2>> GetCertificatesAsync(CancellationToken cancellationToken);
1919
}

src/LettuceEncrypt/Internal/AcmeCertificateFactory.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
using Microsoft.Extensions.Logging;
1313
using Microsoft.Extensions.Options;
1414

15-
#if NETSTANDARD2_0
16-
using IHostApplicationLifetime = Microsoft.Extensions.Hosting.IApplicationLifetime;
17-
#endif
18-
1915
namespace LettuceEncrypt.Internal;
2016

2117
internal class AcmeCertificateFactory

src/LettuceEncrypt/Internal/AcmeCertificateLoader.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
9191
}
9292

9393
private bool LettuceEncryptDomainNamesWereConfigured()
94-
{
95-
return _options.Value.DomainNames
94+
=> _options.Value.DomainNames
9695
.Any(w => !string.Equals("localhost", w, StringComparison.OrdinalIgnoreCase));
97-
}
9896
}

0 commit comments

Comments
 (0)