Skip to content

Commit 0b4aa96

Browse files
committed
fix: allow the CLI to be used in NET6 and NET7
1 parent 3a24155 commit 0b4aa96

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

src/KubeOps.Cli/Certificates/CertificateGenerator.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@ public static (X509Certificate Certificate, AsymmetricCipherKeyPair Key) CreateS
107107
certificateGenerator.AddExtension(
108108
X509Extensions.SubjectAlternativeName,
109109
false,
110-
new GeneralNames(new[]
111-
{
110+
new GeneralNames([
112111
new GeneralName(GeneralName.DnsName, $"{serverName}.{serverNamespace}.svc"),
113112
new GeneralName(GeneralName.DnsName, $"*.{serverNamespace}.svc"),
114113
new GeneralName(GeneralName.DnsName, "*.svc"),
115-
}));
114+
]));
116115

117116
// Subject Public Key
118117
const int keyStrength = 256;

src/KubeOps.Cli/KubeOps.Cli.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
66
<EnablePreviewFeatures>true</EnablePreviewFeatures>
77
</PropertyGroup>
88

src/KubeOps.Cli/Options.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal static class Options
1717
"The path the command will write the files to. If omitted, prints output to console.");
1818

1919
public static readonly Option<string?> TargetFramework = new(
20-
new[] { "--target-framework", "--tfm" },
20+
["--target-framework", "--tfm"],
2121
description: "Target framework of projects in the solution to search for entities. " +
2222
"If omitted, the newest framework is used.");
2323

@@ -32,12 +32,12 @@ internal static class Options
3232
"If omitted, all projects are searched.");
3333

3434
public static readonly Option<bool> Force = new(
35-
new[] { "--force", "-f" },
35+
["--force", "-f"],
3636
() => false,
3737
description: "Do not bother the user with questions and just do it.");
3838

3939
public static readonly Option<bool> ClearOutputPath = new(
40-
new[] { "--clear-out" },
40+
["--clear-out"],
4141
() => false,
4242
description: "Clear the output path before generating resources.");
4343
}

src/KubeOps.Cli/Transpilation/AssemblyLoader.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Reflection;
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.Reflection;
23
using System.Text;
34
using System.Text.RegularExpressions;
45

@@ -22,6 +23,10 @@ namespace KubeOps.Cli.Transpilation;
2223
/// <summary>
2324
/// AssemblyLoader.
2425
/// </summary>
26+
[SuppressMessage(
27+
"Usage",
28+
"CA2252:This API requires opting into preview features",
29+
Justification = "It is the CLI that uses the libraries.")]
2530
internal static partial class AssemblyLoader
2631
{
2732
static AssemblyLoader()
@@ -192,6 +197,10 @@ public static IEnumerable<EntityMetadata> GetConvertedEntities(this MetadataLoad
192197
.Distinct()
193198
.Select(t => context.ToEntityMetadata(t.BaseType!.GenericTypeArguments[0]).Metadata);
194199

200+
#if NET7_0_OR_GREATER
195201
[GeneratedRegex(".*")]
196202
private static partial Regex DefaultRegex();
203+
#else
204+
private static Regex DefaultRegex() => new(".*");
205+
#endif
197206
}

src/KubeOps.Cli/Transpilation/TfmComparer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ namespace KubeOps.Cli.Transpilation;
77
/// </summary>
88
internal sealed partial class TfmComparer : IComparer<string>
99
{
10+
#if NET7_0_OR_GREATER
1011
[GeneratedRegex(
1112
"[(]?(?<tfm>(?<name>(netcoreapp|net|netstandard){1})(?<major>[0-9]+)[.](?<minor>[0-9]+))[)]?",
1213
RegexOptions.Compiled)]
1314
public static partial Regex TfmRegex();
15+
#else
16+
public static Regex TfmRegex() =>
17+
new(
18+
"[(]?(?<tfm>(?<name>(netcoreapp|net|netstandard){1})(?<major>[0-9]+)[.](?<minor>[0-9]+))[)]?",
19+
RegexOptions.Compiled);
20+
#endif
1421

1522
public int Compare(string? x, string? y)
1623
{

0 commit comments

Comments
 (0)