-
Notifications
You must be signed in to change notification settings - Fork 64
[Bootstrapper] Fetch information from dotnet feeds #391
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
base: main
Are you sure you want to change the base?
Changes from 11 commits
71777a1
8c10e2d
ec96336
5ca0b5c
941bb43
80beb9c
9d02fa9
59ee658
c623aa7
6a89e20
12a155a
cbdb765
f46bccc
58580f2
9838ae3
3bbdddc
cbc2b7d
4df438d
7b35bd6
a9a47f5
1697e1e
822f5e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.CommandLine.Parsing; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Bootstrapper | ||
| { | ||
| public abstract class CommandBase | ||
| { | ||
| protected ParseResult _parseResult; | ||
|
|
||
| protected CommandBase(ParseResult parseResult) | ||
| { | ||
| _parseResult = parseResult; | ||
| } | ||
|
|
||
| public abstract int Execute(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.CommandLine.Parsing; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Deployment.DotNet.Releases; | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Bootstrapper.Commands.Install; | ||
|
|
||
| internal class InstallCommand( | ||
| ParseResult parseResult) : CommandBase(parseResult) | ||
| { | ||
| private string _channel = parseResult.ValueForArgument(InstallCommandParser.ChannelArgument); | ||
|
|
||
| public override int Execute() | ||
| { | ||
| string path = Environment.CurrentDirectory; | ||
| ProductCollection productCollection = ProductCollection.GetAsync().Result; | ||
| Product product = productCollection | ||
| .FirstOrDefault(p => string.IsNullOrEmpty(_channel) || p.ProductVersion.Equals(_channel, StringComparison.OrdinalIgnoreCase)); | ||
|
|
||
| if (product == null) | ||
| { | ||
| Console.WriteLine($"No product found for channel: {_channel}"); | ||
| return 1; | ||
| } | ||
|
|
||
| ProductRelease latestRelease = product.GetReleasesAsync().Result | ||
| .Where(release => !release.IsPreview) | ||
| .OrderByDescending(release => release.ReleaseDate) | ||
| .FirstOrDefault(); | ||
|
|
||
| if (latestRelease == null) | ||
| { | ||
| Console.WriteLine($"No releases found for product: {product.ProductName}"); | ||
| return 1; | ||
| } | ||
|
|
||
| Console.WriteLine($"Installing {product.ProductName} {latestRelease.Version}..."); | ||
|
|
||
| foreach (ReleaseComponent component in latestRelease.Components) | ||
| { | ||
| Console.WriteLine($"Installing {component.Name} {component.DisplayVersion}..."); | ||
|
|
||
| ReleaseFile releaseFile = component.Files.FirstOrDefault(file => file.Rid.Equals(Environment.OSVersion.Platform.ToString(), StringComparison.OrdinalIgnoreCase)); | ||
|
|
||
| releaseFile.DownloadAsync(Path.Combine(path, ".net", component.Name)).Wait(); | ||
|
|
||
| Console.WriteLine($"Downloaded {component.Name} {component.DisplayVersion} to {Path.Combine(path, component.Name)}"); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using System.CommandLine; | ||
| using System.CommandLine.Invocation; | ||
| using System.CommandLine.Parsing; | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Bootstrapper.Commands.Install; | ||
|
|
||
| internal class InstallCommandParser | ||
| { | ||
| internal static Argument<string> ChannelArgument = new Argument<string>( | ||
| name: "channel", | ||
| description: "The channel to install sdks for. If not specified, It will take the latest.") | ||
| { | ||
| Arity = ArgumentArity.ZeroOrOne | ||
| }; | ||
|
|
||
| private static readonly Command Command = ConstructCommand(); | ||
|
|
||
| public static Command GetCommand() => Command; | ||
|
|
||
| private static Command ConstructCommand() | ||
| { | ||
| Command command = new("install", "Install SDKs available for installation."); | ||
| command.AddArgument(ChannelArgument); | ||
| command.Handler = CommandHandler.Create((ParseResult parseResult) => | ||
| { | ||
| return new InstallCommand(parseResult).Execute(); | ||
| }); | ||
| return command; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.CommandLine.Parsing; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Deployment.DotNet.Releases; | ||
| using Spectre.Console; | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Bootstrapper.Commands.Search; | ||
|
|
||
| internal class SearchCommand( | ||
| ParseResult parseResult) : CommandBase(parseResult) | ||
| { | ||
| private string _channel = parseResult.ValueForArgument(SearchCommandParser.ChannelArgument); | ||
| private bool _allowPreviews = parseResult.ValueForOption(SearchCommandParser.AllowPreviews); | ||
| public override int Execute() | ||
| { | ||
| List<Product> productCollection = [.. ProductCollection.GetAsync().Result]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The releases.json only changes about once a month. You should consider caching the file on disk and only update it if there's a new version available.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be using the same etag-based cache invalidation system that @nagilson has for the VSCode extension. ETags are the way to handle cache invalidation of HTTP-delivered resources, and we shouldn't be reinventing the wheel.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does https://github.com/dotnet/deployment-tools cache it? I would hope it does so, but at a glance it looks like it does not. I tis what is interfacing with the web request caller API. I would also hope that it handles proxies well. As well as timeouts. If it does not, I would almost question why that should not be implemented over there instead of here. Definitely wouldn't block on this for this PR but would create another issue from it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I've seen, I don't think that it does. I do agree that it would make a lot of sense to implement it there
edvilme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| productCollection = [.. | ||
| productCollection.Where(product => !product.IsOutOfSupport() && (product.SupportPhase != SupportPhase.Preview || _allowPreviews))]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @baronfel Did we decide to only support in support installs? I understand why we'd want to do that, but it seems to limit the product use cases. I would rather emit a warning than block the behavior, but maybe that's ill-advised. |
||
|
|
||
| if (!string.IsNullOrEmpty(_channel)) | ||
| { | ||
| productCollection = [.. productCollection.Where(product => product.ProductVersion.Equals(_channel, StringComparison.OrdinalIgnoreCase))]; | ||
edvilme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| foreach (Product product in productCollection) | ||
| { | ||
| string productHeader = $"{product.ProductName} {product.ProductVersion}"; | ||
| Console.WriteLine(productHeader); | ||
|
|
||
| Table productMetadataTable = new Table() | ||
| .AddColumn("Version") | ||
| .AddColumn("Release Date") | ||
| .AddColumn("SDK") | ||
| .AddColumn("Runtime") | ||
| .AddColumn("ASP.NET Runtime") | ||
| .AddColumn("Windows Desktop Runtime"); | ||
|
|
||
| List<ProductRelease> releases = product.GetReleasesAsync().Result.ToList() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For future reference in the above issue again: Does this cache, and does it handle no internet/timeouts well? The responsibility of ownership here is interesting. Ideally this command could work offline if it has cached information.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I think this does cache, and handles updating and working offline too: |
||
| .Where(relase => !relase.IsPreview || _allowPreviews).ToList(); | ||
|
|
||
| foreach (ProductRelease release in releases) | ||
| { | ||
| productMetadataTable.AddRow( | ||
| release.Version.ToString(), | ||
| release.ReleaseDate.ToString("yyyy-MM-dd"), | ||
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| release.Sdks.FirstOrDefault()?.DisplayVersion ?? "N/A", | ||
| release.Runtime?.DisplayVersion ?? "N/A", | ||
| release.AspNetCoreRuntime?.DisplayVersion ?? "N/A", | ||
| release.WindowsDesktopRuntime?.DisplayVersion ?? "N/A"); | ||
| } | ||
| AnsiConsole.Write(productMetadataTable); | ||
| Console.WriteLine(); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using System.CommandLine; | ||
| using System.CommandLine.Invocation; | ||
| using System.CommandLine.Parsing; | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Bootstrapper.Commands.Search; | ||
|
|
||
| internal class SearchCommandParser | ||
| { | ||
| internal static Argument<string> ChannelArgument = new Argument<string>( | ||
| name: "channel", | ||
| description: "The channel to list sdks for. If not specified, all sdks will be listed.") | ||
| { | ||
| Arity = ArgumentArity.ZeroOrOne | ||
| }; | ||
|
|
||
| internal static Option<bool> AllowPreviews = new Option<bool>( | ||
| "--allow-previews", | ||
| description: "Allow preview releases to be listed."); | ||
|
|
||
| private static readonly Command Command = ConstructCommand(); | ||
| public static Command GetCommand() => Command; | ||
| private static Command ConstructCommand() | ||
| { | ||
| Command command = new("search", "Search for SDKs available for installation."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: It will be easier to keep these strings in the localize file if we start now, but I also don't want to block on this. |
||
| command.AddArgument(ChannelArgument); | ||
| command.AddOption(AllowPreviews); | ||
|
|
||
| command.Handler = CommandHandler.Create((ParseResult parseResult) => | ||
| { | ||
| return new SearchCommand(parseResult).Execute(); | ||
| }); | ||
|
|
||
| return command; | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,9 +22,12 @@ | |
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="$(MicrosoftVisualStudioSetupConfigurationPackageVersion)" /> | ||
| <PackageReference Include="NuGet.Versioning" Version="6.9.1" /> | ||
| <PackageReference Include="Spectre.Console" Version="0.49.1" /> | ||
| <PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" /> | ||
| <PackageReference Include="System.CommandLine.Rendering" Version="0.3.0-alpha.20574.7" /> | ||
| <PackageReference Include="System.Resources.Extensions" Version="8.0.0" /> | ||
| <ProjectReference Include="..\dotnet-core-uninstall\dotnet-core-uninstall.csproj" /> | ||
|
||
| <PackageReference Include="Microsoft.Deployment.DotNet.Releases" Version="1.0.1" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
|
|
@@ -39,6 +42,7 @@ | |
| <EmbeddedResource Update="LocalizableStrings.resx"> | ||
| <Generator>ResXFileCodeGenerator</Generator> | ||
| <LastGenOutput>LocalizableStrings.Designer.cs</LastGenOutput> | ||
| <CustomToolNamespace>Microsoft.DotNet.Tools.Bootstrapper</CustomToolNamespace> | ||
| </EmbeddedResource> | ||
| </ItemGroup> | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.