Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Add netfx 4.8.1, and refactor runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Nov 4, 2023
1 parent 0a68e37 commit 220588d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 21 deletions.
25 changes: 8 additions & 17 deletions src/Squirrel/RuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ public static partial class Runtimes
public enum DotnetRuntimeType
{
/// <summary> The .NET Runtime contains just the components needed to run a console app </summary>
DotNet = 1,
Runtime = 1,
/// <summary> The The ASP.NET Core Runtime enables you to run existing web/server applications </summary>
AspNetCore,
/// <summary> The .NET Desktop Runtime enables you to run existing Windows desktop applications </summary>
WindowsDesktop,
/// <summary> The .NET SDK enables you to compile dotnet applications you intend to run on other systems </summary>
SDK,
}

/// <summary> Runtime installation result code </summary>
Expand Down Expand Up @@ -170,8 +168,7 @@ public class DotnetInfo : RuntimeInfo
public DotnetRuntimeType RuntimeType { get; }

private static readonly Dictionary<DotnetRuntimeType, string> _runtimeShortForm = new() {
{ DotnetRuntimeType.DotNet, "base" },
{ DotnetRuntimeType.SDK, "sdk" },
{ DotnetRuntimeType.Runtime, "runtime" },
{ DotnetRuntimeType.WindowsDesktop, "desktop" },
{ DotnetRuntimeType.AspNetCore, "asp" },
};
Expand Down Expand Up @@ -232,10 +229,9 @@ private static string GetDotnetVersionDir(RuntimeCpu runtimeArch, DotnetRuntimeT
return null;

return runtimeType switch {
DotnetRuntimeType.DotNet => Path.Combine(baseDir, "shared", "Microsoft.NETCore.App"),
DotnetRuntimeType.Runtime => Path.Combine(baseDir, "shared", "Microsoft.NETCore.App"),
DotnetRuntimeType.AspNetCore => Path.Combine(baseDir, "shared", "Microsoft.AspNetCore.App"),
DotnetRuntimeType.WindowsDesktop => Path.Combine(baseDir, "shared", "Microsoft.WindowsDesktop.App"),
DotnetRuntimeType.SDK => Path.Combine(baseDir, "sdk"),
_ => throw new ArgumentOutOfRangeException(nameof(DotnetRuntimeType)),
};
}
Expand Down Expand Up @@ -281,6 +277,8 @@ private bool CheckIsInstalledInBaseDirectory(string baseDirectory)
/// <inheritdoc/>
public override async Task<string> GetDownloadUrl()
{
// Note that GetLatestDotNetVersion should still be fixed for WindowsDesktop as it is the only url that the azure
// blob responds with the latest version. This doesn't matter as all dotnet needed runtimes will have the same latest version.
var latest = await GetLatestDotNetVersion(DotnetRuntimeType.WindowsDesktop, $"{MinVersion.Major}.{MinVersion.Minor}").ConfigureAwait(false);
var architecture = CpuArchitecture switch {
RuntimeCpu.x86 => "x86",
Expand All @@ -291,7 +289,7 @@ public override async Task<string> GetDownloadUrl()
return GetDotNetDownloadUrl(RuntimeType, latest, architecture);
}

private static Regex _dotnetRegex = new Regex(@"^net(?:coreapp)?(?<version>[\d\.]{1,6})(?:-(?<arch>[\w\d]+))?(?:-(?<type>\w+))?$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static Regex _dotnetRegex = new Regex(@"^net(?:coreapp)?(?<version>[\d\.]{1,6})(?:-(?<arch>[a-zA-Z]+\d\d))?(?:-(?<type>[a-zA-Z]+))?$", RegexOptions.IgnoreCase | RegexOptions.Compiled);

/// <summary>
/// Parses a string such as 'net6' or net5.0.14-x86 into a DotnetInfo class capable of checking
Expand Down Expand Up @@ -353,11 +351,6 @@ protected static Version ParseVersion(string input)
throw new ArgumentException("Version must only be a 3-part version string.", nameof(input));

if ((v.Major == 3 && v.Minor == 1) || v.Major >= 5) {
if (v.Major > 8) {
Log.Warn(
$"Runtime version '{input}' was resolved to major version '{v.Major}', but this is greater than any known dotnet version, " +
$"and if this version does not exist this package may fail to install.");
}
return v;
}
throw new ArgumentException($"Version must be 3.1 or >= 5.0. (Actual: {v})", nameof(input));
Expand Down Expand Up @@ -392,10 +385,9 @@ public static async Task<string> GetLatestDotNetVersion(DotnetRuntimeType runtim
// https://github.com/dotnet/install-scripts/blob/main/src/dotnet-install.ps1#L427
// these are case sensitive
string runtime = runtimeType switch {
DotnetRuntimeType.DotNet => "dotnet",
DotnetRuntimeType.Runtime => "dotnet",
DotnetRuntimeType.AspNetCore => "aspnetcore",
DotnetRuntimeType.WindowsDesktop => "WindowsDesktop",
DotnetRuntimeType.SDK => "Sdk",
_ => throw new NotImplementedException(),
};

Expand All @@ -417,13 +409,12 @@ public static string GetDotNetDownloadUrl(DotnetRuntimeType runtimeType, string
{
// https://github.com/dotnet/install-scripts/blob/main/src/dotnet-install.ps1#L619
return runtimeType switch {
DotnetRuntimeType.DotNet => $"{DotNetFeed}/Runtime/{version}/dotnet-runtime-{version}-win-{cpuarch}.exe",
DotnetRuntimeType.Runtime => $"{DotNetFeed}/Runtime/{version}/dotnet-runtime-{version}-win-{cpuarch}.exe",
DotnetRuntimeType.AspNetCore => $"{DotNetFeed}/aspnetcore/Runtime/{version}/aspnetcore-runtime-{version}-win-{cpuarch}.exe",
DotnetRuntimeType.WindowsDesktop =>
new Version(version).Major >= 5
? $"{DotNetFeed}/WindowsDesktop/{version}/windowsdesktop-runtime-{version}-win-{cpuarch}.exe"
: $"{DotNetFeed}/Runtime/{version}/windowsdesktop-runtime-{version}-win-{cpuarch}.exe",
DotnetRuntimeType.SDK => $"{DotNetFeed}/Sdk/{version}/dotnet-sdk-{version}-win-{cpuarch}.exe",
_ => throw new NotImplementedException(),
};
}
Expand Down
16 changes: 15 additions & 1 deletion src/Squirrel/Runtimes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ namespace Squirrel
public static partial class Runtimes
{
/// <summary> Runtime for .NET Framework 4.5 </summary>
[Obsolete("EOL")]
public static readonly FrameworkInfo NETFRAMEWORK45 = new("net45", ".NET Framework 4.5", "http://go.microsoft.com/fwlink/?LinkId=397707", 378389);
/// <summary> Runtime for .NET Framework 4.5.1 </summary>
[Obsolete("EOL")]
public static readonly FrameworkInfo NETFRAMEWORK451 = new("net451", ".NET Framework 4.5.1", "http://go.microsoft.com/fwlink/?LinkId=397707", 378675);
/// <summary> Runtime for .NET Framework 4.5.2 </summary>
[Obsolete("EOL")]
public static readonly FrameworkInfo NETFRAMEWORK452 = new("net452", ".NET Framework 4.5.2", "http://go.microsoft.com/fwlink/?LinkId=397707", 379893);
/// <summary> Runtime for .NET Framework 4.6 </summary>
[Obsolete("EOL")]
public static readonly FrameworkInfo NETFRAMEWORK46 = new("net46", ".NET Framework 4.6", "http://go.microsoft.com/fwlink/?LinkId=780596", 393295);
/// <summary> Runtime for .NET Framework 4.6.1 </summary>
[Obsolete("EOL")]
public static readonly FrameworkInfo NETFRAMEWORK461 = new("net461", ".NET Framework 4.6.1", "http://go.microsoft.com/fwlink/?LinkId=780596", 394254);
/// <summary> Runtime for .NET Framework 4.6.2 </summary>
public static readonly FrameworkInfo NETFRAMEWORK462 = new("net462", ".NET Framework 4.6.2", "http://go.microsoft.com/fwlink/?LinkId=780596", 394802);
Expand All @@ -33,15 +38,21 @@ public static partial class Runtimes
public static readonly FrameworkInfo NETFRAMEWORK472 = new("net472", ".NET Framework 4.7.2", "http://go.microsoft.com/fwlink/?LinkId=863262", 461808);
/// <summary> Runtime for .NET Framework 4.8 </summary>
public static readonly FrameworkInfo NETFRAMEWORK48 = new("net48", ".NET Framework 4.8", "http://go.microsoft.com/fwlink/?LinkId=2085155", 528040);
/// <summary> Runtime for .NET Framework 4.8.1 </summary>
public static readonly FrameworkInfo NETFRAMEWORK481 = new("net481", ".NET Framework 4.8.1", "http://go.microsoft.com/fwlink/?LinkId=2203304", 533320);


/// <summary> Runtime for .NET Core 3.1 Desktop Runtime (x86) </summary>
[Obsolete("EOL")]
public static readonly DotnetInfo DOTNETCORE31_X86 = new("3.1", RuntimeCpu.x86); // eg. netcoreapp3.1-x86
/// <summary> Runtime for .NET Core 3.1 Desktop Runtime (x64) </summary>
[Obsolete("EOL")]
public static readonly DotnetInfo DOTNETCORE31_X64 = new("3.1", RuntimeCpu.x64); // eg. netcoreapp3.1-x64
/// <summary> Runtime for .NET 5.0 Desktop Runtime (x86) </summary>
[Obsolete("EOL")]
public static readonly DotnetInfo DOTNET5_X86 = new("5.0", RuntimeCpu.x86); // eg. net5.0-x86
/// <summary> Runtime for .NET 5.0 Desktop Runtime (x64) </summary>
[Obsolete("EOL")]
public static readonly DotnetInfo DOTNET5_X64 = new("5.0", RuntimeCpu.x64); // eg. net5.0-x64
/// <summary> Runtime for .NET 6.0 Desktop Runtime (x86) </summary>
public static readonly DotnetInfo DOTNET6_X86 = new("6.0.2", RuntimeCpu.x86); // eg. net6.0-x86
Expand All @@ -51,7 +62,10 @@ public static partial class Runtimes
public static readonly DotnetInfo DOTNET7_X86 = new("7.0", RuntimeCpu.x86); // eg. net7.0-x86
/// <summary> Runtime for .NET 7.0 Desktop Runtime (x64) </summary>
public static readonly DotnetInfo DOTNET7_X64 = new("7.0", RuntimeCpu.x64); // eg. net7.0-x64

/// <summary> Runtime for .NET 8.0 Desktop Runtime (x86) </summary>
public static readonly DotnetInfo DOTNET8_X86 = new("8.0", RuntimeCpu.x86); // eg. net8.0-x86
/// <summary> Runtime for .NET 8.0 Desktop Runtime (x64) </summary>
public static readonly DotnetInfo DOTNET8_X64 = new("8.0", RuntimeCpu.x64); // eg. net8.0-x64

/// <summary> Runtime for Visual C++ 2010 Redistributable (x86) </summary>
public static readonly VCRedist00 VCREDIST100_X86 = new("vcredist100-x86", "Visual C++ 2010 Redistributable (x86)", new(10, 00, 40219), RuntimeCpu.x86,
Expand Down
50 changes: 47 additions & 3 deletions test/RuntimeTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Xunit;

Expand All @@ -24,9 +26,10 @@ public class RuntimeTests
[InlineData("net6.0.1-x86", "net6.0.1-x86-desktop")]
[InlineData("net6.0.0", "net6-x64-desktop")]
[InlineData("net6.0-x64-desktop", "net6.0.2-x64-desktop")]
[InlineData("net7.0-x64-base", "net7-x64-base")]
[InlineData("net7.0-x64-runtime", "net7-x64-runtime")]
[InlineData("net7.0-x64-asp", "net7-x64-asp")]
[InlineData("net7.0-x64-sdk", "net7-x64-sdk")]
[InlineData("net7.0-desktop", "net7-x64-desktop")]
[InlineData("net7.0-runtime", "net7-x64-runtime")]
public void DotnetParsesValidVersions(string input, string expected)
{
var p = Runtimes.DotnetInfo.Parse(input);
Expand All @@ -37,6 +40,7 @@ public void DotnetParsesValidVersions(string input, string expected)
[InlineData("net3.2")]
[InlineData("net4.9")]
[InlineData("net6.0.0.4")]
[InlineData("net7.0-x64-base")]
[InlineData("net6-basd")]
[InlineData("net6-x64-aakaka")]
public void DotnetParseThrowsInvalidVersion(string input)
Expand All @@ -61,11 +65,51 @@ public void DotnetParseThrowsInvalidVersion(string input)
[InlineData("", false)]
[InlineData(null, false)]
[InlineData("net6-x64", true)]
[InlineData("net6-x64-sdk", true)]
[InlineData("net6-x64-runtime", true)]
[InlineData("net6-x64-desktop", true)]
public void GetRuntimeTests(string input, bool expected)
{
var dn = Runtimes.GetRuntimeByName(input);
Assert.Equal(expected, dn != null);
}

[Theory]
[InlineData("3.1", RuntimeCpu.x86, Runtimes.DotnetRuntimeType.WindowsDesktop)]
[InlineData("3.1", RuntimeCpu.x86, Runtimes.DotnetRuntimeType.Runtime)]
[InlineData("3.1", RuntimeCpu.x86, Runtimes.DotnetRuntimeType.AspNetCore)]
[InlineData("3.1", RuntimeCpu.x64, Runtimes.DotnetRuntimeType.WindowsDesktop)]
[InlineData("3.1", RuntimeCpu.x64, Runtimes.DotnetRuntimeType.Runtime)]
[InlineData("3.1", RuntimeCpu.x64, Runtimes.DotnetRuntimeType.AspNetCore)]
[InlineData("5.0", RuntimeCpu.x86, Runtimes.DotnetRuntimeType.WindowsDesktop)]
[InlineData("5.0", RuntimeCpu.x86, Runtimes.DotnetRuntimeType.Runtime)]
[InlineData("5.0", RuntimeCpu.x86, Runtimes.DotnetRuntimeType.AspNetCore)]
[InlineData("5.0", RuntimeCpu.x64, Runtimes.DotnetRuntimeType.WindowsDesktop)]
[InlineData("5.0", RuntimeCpu.x64, Runtimes.DotnetRuntimeType.Runtime)]
[InlineData("5.0", RuntimeCpu.x64, Runtimes.DotnetRuntimeType.AspNetCore)]
[InlineData("7.0", RuntimeCpu.x86, Runtimes.DotnetRuntimeType.WindowsDesktop)]
[InlineData("7.0", RuntimeCpu.x86, Runtimes.DotnetRuntimeType.Runtime)]
[InlineData("7.0", RuntimeCpu.x86, Runtimes.DotnetRuntimeType.AspNetCore)]
[InlineData("7.0", RuntimeCpu.x64, Runtimes.DotnetRuntimeType.WindowsDesktop)]
[InlineData("7.0", RuntimeCpu.x64, Runtimes.DotnetRuntimeType.Runtime)]
[InlineData("7.0", RuntimeCpu.x64, Runtimes.DotnetRuntimeType.AspNetCore)]
public void MicrosoftReturnsValidDotnetDownload(string minversion, RuntimeCpu architecture, Runtimes.DotnetRuntimeType runtimeType)
{
var dni = new Runtimes.DotnetInfo(minversion, architecture, runtimeType);
var url = dni.GetDownloadUrl().Result;

Assert.Contains(minversion, url, StringComparison.OrdinalIgnoreCase);
Assert.Contains(architecture.ToString(), url, StringComparison.OrdinalIgnoreCase);

if (runtimeType == Runtimes.DotnetRuntimeType.Runtime)
Assert.Matches(@"/dotnet-runtime-\d", url);
else if (runtimeType == Runtimes.DotnetRuntimeType.AspNetCore)
Assert.Matches(@"/aspnetcore-runtime-\d", url);
else if (runtimeType == Runtimes.DotnetRuntimeType.WindowsDesktop)
Assert.Matches(@"/windowsdesktop-runtime-\d", url);

using var hc = new HttpClient();
var result = hc.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).Result;
result.EnsureSuccessStatusCode();
}
}
}

0 comments on commit 220588d

Please sign in to comment.