Skip to content

Commit

Permalink
Add ability to download latest preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Woodward committed Sep 1, 2019
1 parent e322aaf commit a974314
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 23 deletions.
19 changes: 17 additions & 2 deletions README.md
Expand Up @@ -9,10 +9,25 @@ To install globally:
$ dotnet tool install -g installsdkglobaltool
```

Usage:
You can also find InstallSdkGlobalTool [on NuGet here](https://www.nuget.org/packages/InstallSdkGlobalTool/).

## Usage:

You can use this tool to download and install .NET Core SDK versions based on a variety of ways, these are:

### Install based on global.json

1. Navigate to a directory that contains a `global.json` file in your terminal.
2. Run `$ dotnet install-sdk`
3. Sit back and relax as the Install SDK global tool installs the version of the SDK required.

The .NET Core Install SDK global tool will then download and launch the installer for the version of the SDK dictated by the global.json file.

### Install latest .NET Core SDK Preview

1. Run `$ dotnet install-sdk --latest-preview` from any directory

The .NET core Install SDK global tool will then download and lauch the installer for the latest preview of the .NET Core SDK.

##Contributions

Big thanks to [@stuartblang](https://twitter.com/stuartblang) who contributed loads to this.
9 changes: 9 additions & 0 deletions src/DotNetInstallSdk/Acquirables/AcquireResult.cs
@@ -0,0 +1,9 @@
namespace DotNet.InstallSdk.Acquirables
{
public class AcquireResult
{
public string Version { get; set; }

public string ChannelJson { get; set; }
}
}
7 changes: 0 additions & 7 deletions src/DotNetInstallSdk/Acquirables/GlobalJsonVersion.cs
Expand Up @@ -42,11 +42,4 @@ public override async Task<AcquireResult> Fetch(HttpClient httpClient)
};
}
}

public class AcquireResult
{
public string Version { get; set; }

public string ChannelJson { get; set; }
}
}
28 changes: 28 additions & 0 deletions src/DotNetInstallSdk/Acquirables/LatestPreviewVersion.cs
@@ -0,0 +1,28 @@
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;

namespace DotNet.InstallSdk.Acquirables
{
public class LatestPreviewVersion : Acquirable
{
public LatestPreviewVersion(ITextWriter writer)
{
}

public override async Task<AcquireResult> Fetch(HttpClient httpClient)
{
using var releasesResponse = await JsonDocument.ParseAsync(await httpClient.GetStreamAsync(ReleaseIndex));

var channel = releasesResponse.RootElement.GetProperty("releases-index").EnumerateArray()
.First(x => x.GetProperty("support-phase").GetString() == "preview");

return new AcquireResult
{
ChannelJson = channel.GetProperty("releases.json").GetString(),
Version = channel.GetProperty("latest-sdk").GetString()
};
}
}
}
4 changes: 2 additions & 2 deletions src/DotNetInstallSdk/DotNetInstallSdk.csproj
Expand Up @@ -8,10 +8,10 @@
<PackageTags>global tool;install sdk</PackageTags>
<ToolCommandName>dotnet-install-sdk</ToolCommandName>
<LangVersion>8</LangVersion>
<VersionPrefix>2.0.1</VersionPrefix>
<VersionPrefix>2.1.0</VersionPrefix>
<PackageId>InstallSdkGlobalTool</PackageId>
<Authors>Joseph Woodward, Stuart Lang</Authors>
<Description>A .NET Core Global Tool for installing .NET Core SDK versions based on global.json files</Description>
<Description>A .NET Core Global Tool for installing .NET Core SDK versions base on lots of different requirements</Description>
<PackageProjectUrl>https://github.com/JosephWoodward/DotNetInstallSdkGlobalTool/</PackageProjectUrl>
<RepositoryUrl>https://github.com/JosephWoodward/DotNetInstallSdkGlobalTool.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
9 changes: 3 additions & 6 deletions src/DotNetInstallSdk/InstallSdkTool.cs
@@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
Expand All @@ -7,16 +8,12 @@ namespace DotNet.InstallSdk
{
public static class InstallSdkTool
{
public static void Run(CommandLineArguments args)
public static void Run(Acquirable acquirable, ConsoleTextWriter writer)
{
var writer = new ConsoleTextWriter();

try
{
var v = new GlobalJsonVersion(writer);

var sdkAcquirer = new SdkAcquirer(new HttpClient(), writer, new InstallerLauncher(), new PlatformIdentifier());
sdkAcquirer.Acquire(v).GetAwaiter().GetResult();
sdkAcquirer.Acquire(acquirable).GetAwaiter().GetResult();
}
catch (FileNotFoundException e)
{
Expand Down
21 changes: 15 additions & 6 deletions src/DotNetInstallSdk/Program.cs
@@ -1,4 +1,5 @@
using McMaster.Extensions.CommandLineUtils;
using DotNet.InstallSdk.Acquirables;
using McMaster.Extensions.CommandLineUtils;

namespace DotNet.InstallSdk
{
Expand All @@ -7,20 +8,28 @@ class Program
public static int Main(string[] args)
=> CommandLineApplication.Execute<Program>(args);

/*
[Option("-LP|--latest-preview", Description = "Install the latest preview version of the .NET Core SDK")]
public bool LatestPreview { get; } = false;

/*
[Option("-L|--latest", Description = "Install the latest non-preview version of the .NET Core SDK")]
public bool Latest { get; } = false;
*/
private void OnExecute()
{
InstallSdkTool.Run(new CommandLineArguments
var writer = new ConsoleTextWriter();

Acquirable a;
if (LatestPreview)
{
a = new LatestPreviewVersion(writer);
}
else
{
Latest = false,
LatestPreview = false
});
a = new GlobalJsonVersion(writer);
}

InstallSdkTool.Run(a, writer);
}
}
}

0 comments on commit a974314

Please sign in to comment.