Skip to content

Commit 60d1ab4

Browse files
AOT compatible: make NuGet.Commandline.Xplat Aot compatible (#7207)
1 parent efaba6a commit 60d1ab4

6 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ private static List<PackageSource> GetPackageSources(ISettings settings, IEnumer
268268
return packageSources;
269269
}
270270

271-
private static string GetEnumValues<T>() where T : Enum
271+
private static string GetEnumValues<T>() where T : struct, Enum
272272
{
273-
var enumValues = ((T[])Enum.GetValues(typeof(T)))
273+
var enumValues = Enum.GetValues<T>()
274274
.Select(x => x.ToString());
275275

276276
return string.Join(", ", enumValues).ToLower(CultureInfo.CurrentCulture);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Text.Json.Serialization;
5+
6+
namespace NuGet.CommandLine.XPlat
7+
{
8+
[JsonSerializable(typeof(SearchMainOutput))]
9+
internal partial class PackageSearchJsonContext : JsonSerializerContext
10+
{
11+
}
12+
}

src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/PackageSearch/JsonFormat/PackageSearchProblem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class PackageSearchProblem
1313
public string Text { get; private set; }
1414

1515
[JsonPropertyName("problemType")]
16-
[JsonConverter(typeof(JsonStringEnumConverter))]
16+
[JsonConverter(typeof(JsonStringEnumConverter<PackageSearchProblemType>))]
1717
public PackageSearchProblemType ProblemType { get; }
1818

1919
internal PackageSearchProblem(PackageSearchProblemType packageSearchProblemType, string text)

src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/PackageSearch/PackageSearchResultJsonRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void Finish()
5454
Converters = { new SearchResultPackagesConverter(_verbosity, _exactMatch) },
5555
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
5656
};
57-
var json = JsonSerializer.Serialize(_packageSearchMainOutput, options);
57+
var json = JsonSerializer.Serialize(_packageSearchMainOutput, new PackageSearchJsonContext(options).SearchMainOutput);
5858
_logger.LogMinimal(json);
5959
}
6060

src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Signing/SignCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private static StoreLocation ValidateAndParseStoreLocation(CommandOption locatio
184184
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
185185
Strings.Err_InvalidValue,
186186
location.LongName,
187-
string.Join(",", Enum.GetValues(typeof(StoreLocation)).Cast<StoreLocation>().ToList())));
187+
string.Join(",", Enum.GetValues<StoreLocation>().ToList())));
188188
}
189189
}
190190

@@ -203,7 +203,7 @@ private static StoreName ValidateAndParseStoreName(CommandOption store)
203203
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
204204
Strings.Err_InvalidValue,
205205
store.LongName,
206-
string.Join(",", Enum.GetValues(typeof(StoreName)).Cast<StoreName>().ToList())));
206+
string.Join(",", Enum.GetValues<StoreName>().ToList())));
207207
}
208208
}
209209

src/NuGet.Core/NuGet.CommandLine.XPlat/NuGet.CommandLine.XPlat.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<Shipping>true</Shipping>
88
<PackProject>true</PackProject>
99
<XPLATProject>true</XPLATProject>
10-
<IsAotCompatible>false</IsAotCompatible>
1110
<UseMSBuildLocator Condition=" '$(UseMSBuildLocator)' == '' And '$(Configuration)' == 'Debug' and '$(CI)' != 'true' ">true</UseMSBuildLocator>
1211
<!-- Microsoft.Extensions.CommandLineUtils.Sources causes nullability warnings, so we have to disable it for the project and enable in each file until we can remove the package -->
1312
<Nullable>disable</Nullable>

0 commit comments

Comments
 (0)