Skip to content

Commit 72f4fb4

Browse files
authored
Installer: Get channels from release.json, and other improvements (#51485)
2 parents 11265f1 + 8527690 commit 72f4fb4

File tree

15 files changed

+74
-169
lines changed

15 files changed

+74
-169
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<PackageVersion Include="runtime.linux-x64.Microsoft.NETCore.DotNetHostResolver" Version="$(MicrosoftNETCoreDotNetHostResolverPackageVersion)" />
115115
<PackageVersion Include="runtime.osx-x64.Microsoft.NETCore.DotNetHostResolver" Version="$(MicrosoftNETCoreDotNetHostResolverPackageVersion)" />
116116
<PackageVersion Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersPackageVersion)" />
117-
<PackageVersion Include="Spectre.Console" Version="0.48.0" />
117+
<PackageVersion Include="Spectre.Console" Version="0.53.0" />
118118
<PackageVersion Include="System.CodeDom" Version="$(SystemCodeDomPackageVersion)" />
119119
<PackageVersion Include="System.CommandLine" Version="$(SystemCommandLineVersion)" />
120120
<PackageVersion Include="System.CommandLine.NamingConventionBinder" Version="$(SystemCommandLineNamingConventionBinderVersion)" />

dnup.slnf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"src\\Installer\\dnup\\dnup.csproj",
66
"src\\Installer\\Microsoft.Dotnet.Installation\\Microsoft.Dotnet.Installation.csproj",
77
"test\\dnup.Tests\\dnup.Tests.csproj",
8-
"src\\Resolvers\\Microsoft.DotNet.NativeWrapper\\Microsoft.DotNet.NativeWrapper.csproj
8+
"src\\Resolvers\\Microsoft.DotNet.NativeWrapper\\Microsoft.DotNet.NativeWrapper.csproj"
99
]
1010
}
1111
}

src/Installer/Microsoft.Dotnet.Installation/IDotnetReleaseInfoProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.Dotnet.Installation;
1010

1111
public interface IDotnetReleaseInfoProvider
1212
{
13-
IEnumerable<string> GetAvailableChannels();
13+
IEnumerable<string> GetSupportedChannels();
1414

1515
ReleaseVersion? GetLatestVersion(InstallComponent component, string channel);
1616

src/Installer/Microsoft.Dotnet.Installation/Internal/DotnetReleaseInfoProvider.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ namespace Microsoft.Dotnet.Installation.Internal;
1010

1111
internal class DotnetReleaseInfoProvider : IDotnetReleaseInfoProvider
1212
{
13-
public IEnumerable<string> GetAvailableChannels() => throw new NotImplementedException();
13+
public IEnumerable<string> GetSupportedChannels()
14+
{
15+
var releaseManifest = new ReleaseManifest();
16+
return releaseManifest.GetSupportedChannels();
17+
}
1418
public ReleaseVersion? GetLatestVersion(InstallComponent component, string channel)
1519
{
1620
var releaseManifest = new ReleaseManifest();

src/Installer/Microsoft.Dotnet.Installation/Internal/ReleaseManifest.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Net;
88
using System.Net.Http;
99
using System.Net.Http.Headers;
10+
using System.Runtime.CompilerServices;
1011
using System.Security.Cryptography;
1112
using System.Text;
1213
using System.Threading;
@@ -53,6 +54,31 @@ internal class ReleaseManifest(HttpClient httpClient) : IDisposable
5354
return (major, minor, featureBand, isFullySpecified);
5455
}
5556

57+
public IEnumerable<string> GetSupportedChannels()
58+
{
59+
60+
return ["latest", "preview", "lts", "sts",
61+
..GetProductCollection()
62+
.Where(p => p.IsSupported)
63+
.OrderByDescending(p => p.LatestReleaseVersion)
64+
.SelectMany(GetChannelsForProduct)
65+
];
66+
67+
static IEnumerable<string> GetChannelsForProduct(Product product)
68+
{
69+
return [product.ProductVersion,
70+
..product.GetReleasesAsync().GetAwaiter().GetResult()
71+
.SelectMany(r => r.Sdks)
72+
.Select(sdk => sdk.Version)
73+
.OrderByDescending(v => v)
74+
.Select(v => $"{v.Major}.{v.Minor}.{(v.Patch / 100)}xx")
75+
.Distinct()
76+
.ToList()
77+
];
78+
}
79+
80+
}
81+
5682
/// <summary>
5783
/// Finds the latest fully specified version for a given channel string (major, major.minor, or feature band).
5884
/// </summary>
@@ -64,17 +90,17 @@ internal class ReleaseManifest(HttpClient httpClient) : IDisposable
6490
if (string.Equals(channel.Name, "lts", StringComparison.OrdinalIgnoreCase) || string.Equals(channel.Name, "sts", StringComparison.OrdinalIgnoreCase))
6591
{
6692
var releaseType = string.Equals(channel.Name, "lts", StringComparison.OrdinalIgnoreCase) ? ReleaseType.LTS : ReleaseType.STS;
67-
var productIndex = ProductCollection.GetAsync().GetAwaiter().GetResult();
93+
var productIndex = GetProductCollection();
6894
return GetLatestVersionByReleaseType(productIndex, releaseType, component);
6995
}
7096
else if (string.Equals(channel.Name, "preview", StringComparison.OrdinalIgnoreCase))
7197
{
72-
var productIndex = ProductCollection.GetAsync().GetAwaiter().GetResult();
98+
var productIndex = GetProductCollection();
7399
return GetLatestPreviewVersion(productIndex, component);
74100
}
75101
else if (string.Equals(channel.Name, "latest", StringComparison.OrdinalIgnoreCase))
76102
{
77-
var productIndex = ProductCollection.GetAsync().GetAwaiter().GetResult();
103+
var productIndex = GetProductCollection();
78104
return GetLatestActiveVersion(productIndex, component);
79105
}
80106

@@ -93,7 +119,7 @@ internal class ReleaseManifest(HttpClient httpClient) : IDisposable
93119
}
94120

95121
// Load the index manifest
96-
var index = ProductCollection.GetAsync().GetAwaiter().GetResult();
122+
var index = GetProductCollection();
97123
if (minor < 0)
98124
{
99125
return GetLatestVersionForMajorOrMajorMinor(index, major, component); // Major Only (e.g., "9")

src/Installer/dnup/Commands/Sdk/Install/EnvironmentVariableMockDotnetInstaller.cs

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/Installer/dnup/Commands/Sdk/Install/EnvironmentVariableMockReleaseInfoProvider.cs

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/Installer/dnup/Commands/Sdk/Install/SdkInstallCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal class SdkInstallCommand(ParseResult result) : CommandBase(result)
2323
private readonly bool _noProgress = result.GetValue(SdkInstallCommandParser.NoProgressOption);
2424

2525
private readonly IDotnetInstallManager _dotnetInstaller = new DotnetInstallManager();
26-
private readonly IDotnetReleaseInfoProvider _releaseInfoProvider = new EnvironmentVariableMockReleaseInfoProvider();
26+
private readonly IDotnetReleaseInfoProvider _releaseInfoProvider = new DotnetReleaseInfoProvider();
2727
private readonly ManifestChannelVersionResolver _channelVersionResolver = new ManifestChannelVersionResolver();
2828

2929
public override int Execute()
@@ -113,7 +113,7 @@ public override int Execute()
113113
if (_interactive)
114114
{
115115

116-
SpectreAnsiConsole.WriteLine("Available supported channels: " + string.Join(' ', _releaseInfoProvider.GetAvailableChannels()));
116+
SpectreAnsiConsole.WriteLine("Available supported channels: " + string.Join(' ', _releaseInfoProvider.GetSupportedChannels()));
117117
SpectreAnsiConsole.WriteLine("You can also specify a specific version (for example 9.0.304).");
118118

119119
resolvedChannel = SpectreAnsiConsole.Prompt(

src/Installer/dnup/IDotnetInstallManager.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ public class GlobalJsonInfo
4343
public string? SdkVersion => GlobalJsonContents?.Sdk?.Version;
4444
public bool? AllowPrerelease => GlobalJsonContents?.Sdk?.AllowPrerelease;
4545
public string? RollForward => GlobalJsonContents?.Sdk?.RollForward;
46-
public string? SdkPath => (GlobalJsonContents?.Sdk?.Paths is not null && GlobalJsonContents.Sdk.Paths.Length > 0) ? GlobalJsonContents.Sdk.Paths[0] : null;
46+
public string? SdkPath
47+
{
48+
get
49+
{
50+
return (GlobalJsonContents?.Sdk?.Paths is not null && GlobalJsonContents.Sdk.Paths.Length > 0) ?
51+
Path.GetFullPath(GlobalJsonContents.Sdk.Paths[0], GlobalJsonPath!) : null;
52+
}
53+
}
4754
}
4855

4956
public record DotnetInstallRootConfiguration(

src/Installer/dnup/dnup.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<PublishAot>true</PublishAot>
9+
<TrimmerSingleWarn>false</TrimmerSingleWarn>
910

1011
<!-- Strong naming not needed on .NET Core -->
1112
<NoWarn>$(NoWarn);CS8002</NoWarn>

0 commit comments

Comments
 (0)