Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<PackageVersion Include="runtime.linux-x64.Microsoft.NETCore.DotNetHostResolver" Version="$(MicrosoftNETCoreDotNetHostResolverPackageVersion)" />
<PackageVersion Include="runtime.osx-x64.Microsoft.NETCore.DotNetHostResolver" Version="$(MicrosoftNETCoreDotNetHostResolverPackageVersion)" />
<PackageVersion Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersPackageVersion)" />
<PackageVersion Include="Spectre.Console" Version="0.48.0" />
<PackageVersion Include="Spectre.Console" Version="0.53.0" />
<PackageVersion Include="System.CodeDom" Version="$(SystemCodeDomPackageVersion)" />
<PackageVersion Include="System.CommandLine" Version="$(SystemCommandLineVersion)" />
<PackageVersion Include="System.CommandLine.NamingConventionBinder" Version="$(SystemCommandLineNamingConventionBinderVersion)" />
Expand Down
2 changes: 1 addition & 1 deletion dnup.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"src\\Installer\\dnup\\dnup.csproj",
"src\\Installer\\Microsoft.Dotnet.Installation\\Microsoft.Dotnet.Installation.csproj",
"test\\dnup.Tests\\dnup.Tests.csproj",
"src\\Resolvers\\Microsoft.DotNet.NativeWrapper\\Microsoft.DotNet.NativeWrapper.csproj
"src\\Resolvers\\Microsoft.DotNet.NativeWrapper\\Microsoft.DotNet.NativeWrapper.csproj"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Dotnet.Installation;

public interface IDotnetReleaseInfoProvider
{
IEnumerable<string> GetAvailableChannels();
IEnumerable<string> GetSupportedChannels();

ReleaseVersion? GetLatestVersion(InstallComponent component, string channel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ namespace Microsoft.Dotnet.Installation.Internal;

internal class DotnetReleaseInfoProvider : IDotnetReleaseInfoProvider
{
public IEnumerable<string> GetAvailableChannels() => throw new NotImplementedException();
public IEnumerable<string> GetSupportedChannels()
{
var releaseManifest = new ReleaseManifest();
return releaseManifest.GetSupportedChannels();
}
public ReleaseVersion? GetLatestVersion(InstallComponent component, string channel)
{
var releaseManifest = new ReleaseManifest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -53,6 +54,31 @@ internal class ReleaseManifest(HttpClient httpClient) : IDisposable
return (major, minor, featureBand, isFullySpecified);
}

public IEnumerable<string> GetSupportedChannels()
{

return ["latest", "preview", "lts", "sts",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep this in a data structure of special keyword channels we support.

..GetProductCollection()
.Where(p => p.IsSupported)
.OrderByDescending(p => p.LatestReleaseVersion)
.SelectMany(GetChannelsForProduct)
];

static IEnumerable<string> GetChannelsForProduct(Product product)
{
return [product.ProductVersion,
..product.GetReleasesAsync().GetAwaiter().GetResult()
.SelectMany(r => r.Sdks)
.Select(sdk => sdk.Version)
.OrderByDescending(v => v)
.Select(v => $"{v.Major}.{v.Minor}.{(v.Patch / 100)}xx")
.Distinct()
.ToList()
];
}

}

/// <summary>
/// Finds the latest fully specified version for a given channel string (major, major.minor, or feature band).
/// </summary>
Expand All @@ -64,17 +90,17 @@ internal class ReleaseManifest(HttpClient httpClient) : IDisposable
if (string.Equals(channel.Name, "lts", StringComparison.OrdinalIgnoreCase) || string.Equals(channel.Name, "sts", StringComparison.OrdinalIgnoreCase))
{
var releaseType = string.Equals(channel.Name, "lts", StringComparison.OrdinalIgnoreCase) ? ReleaseType.LTS : ReleaseType.STS;
var productIndex = ProductCollection.GetAsync().GetAwaiter().GetResult();
var productIndex = GetProductCollection();
return GetLatestVersionByReleaseType(productIndex, releaseType, component);
}
else if (string.Equals(channel.Name, "preview", StringComparison.OrdinalIgnoreCase))
{
var productIndex = ProductCollection.GetAsync().GetAwaiter().GetResult();
var productIndex = GetProductCollection();
return GetLatestPreviewVersion(productIndex, component);
}
else if (string.Equals(channel.Name, "latest", StringComparison.OrdinalIgnoreCase))
{
var productIndex = ProductCollection.GetAsync().GetAwaiter().GetResult();
var productIndex = GetProductCollection();
return GetLatestActiveVersion(productIndex, component);
}

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

// Load the index manifest
var index = ProductCollection.GetAsync().GetAwaiter().GetResult();
var index = GetProductCollection();
if (minor < 0)
{
return GetLatestVersionForMajorOrMajorMinor(index, major, component); // Major Only (e.g., "9")
Expand Down

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions src/Installer/dnup/Commands/Sdk/Install/SdkInstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class SdkInstallCommand(ParseResult result) : CommandBase(result)
private readonly bool _noProgress = result.GetValue(SdkInstallCommandParser.NoProgressOption);

private readonly IDotnetInstallManager _dotnetInstaller = new DotnetInstallManager();
private readonly IDotnetReleaseInfoProvider _releaseInfoProvider = new EnvironmentVariableMockReleaseInfoProvider();
private readonly IDotnetReleaseInfoProvider _releaseInfoProvider = new DotnetReleaseInfoProvider();
private readonly ManifestChannelVersionResolver _channelVersionResolver = new ManifestChannelVersionResolver();

public override int Execute()
Expand Down Expand Up @@ -113,7 +113,7 @@ public override int Execute()
if (_interactive)
{

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

resolvedChannel = SpectreAnsiConsole.Prompt(
Expand Down
9 changes: 8 additions & 1 deletion src/Installer/dnup/IDotnetInstallManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ public class GlobalJsonInfo
public string? SdkVersion => GlobalJsonContents?.Sdk?.Version;
public bool? AllowPrerelease => GlobalJsonContents?.Sdk?.AllowPrerelease;
public string? RollForward => GlobalJsonContents?.Sdk?.RollForward;
public string? SdkPath => (GlobalJsonContents?.Sdk?.Paths is not null && GlobalJsonContents.Sdk.Paths.Length > 0) ? GlobalJsonContents.Sdk.Paths[0] : null;
public string? SdkPath
{
get
{
return (GlobalJsonContents?.Sdk?.Paths is not null && GlobalJsonContents.Sdk.Paths.Length > 0) ?
Path.GetFullPath(GlobalJsonContents.Sdk.Paths[0], GlobalJsonPath!) : null;
}
}
}

public record DotnetInstallRootConfiguration(
Expand Down
1 change: 1 addition & 0 deletions src/Installer/dnup/dnup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<TrimmerSingleWarn>false</TrimmerSingleWarn>

<!-- Strong naming not needed on .NET Core -->
<NoWarn>$(NoWarn);CS8002</NoWarn>
Expand Down
2 changes: 1 addition & 1 deletion src/Resolvers/Microsoft.DotNet.NativeWrapper/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static Interop()
// construction so that subsequent P/Invokes can find it.
private static void PreloadWindowsLibrary(string dllFileName)
{
string? basePath = Path.GetDirectoryName(typeof(Interop).Assembly.Location);
string? basePath = AppContext.BaseDirectory;
string architecture = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
string dllPath = Path.Combine(basePath ?? string.Empty, architecture, $"{dllFileName}.dll");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>$(ResolverTargetFramework);net472</TargetFrameworks>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my understanding, why did we use net8.0 here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I didn't have the condition it gave me an error saying the property wasn't supported for .NET Framework, and the error suggested this condition. I think the property is maybe supported on .NET 6 and higher.

</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ internal void Initialize(IntPtr info, IntPtr resultContext)
var runtimes = new hostfxr_dotnet_environment_framework_info[infoStruct.framework_count];
for (var i = 0; i < (int)infoStruct.framework_count; i++)
{
var pointer = new IntPtr(infoStruct.frameworks.ToInt64() + i * Marshal.SizeOf(typeof(hostfxr_dotnet_environment_framework_info)));
var pointer = new IntPtr(infoStruct.frameworks.ToInt64() + i * Marshal.SizeOf<hostfxr_dotnet_environment_framework_info>());
runtimes[i] = Marshal.PtrToStructure<hostfxr_dotnet_environment_framework_info>(pointer);
}
RuntimeInfo = runtimes.Select(runtime => new NetRuntimeInfo(runtime.name, runtime.version, runtime.path));

var sdks = new hostfxr_dotnet_environment_sdk_info[infoStruct.sdk_count];
for (var i = 0; i < (int)infoStruct.sdk_count; i++)
{
var pointer = new IntPtr(infoStruct.sdks.ToInt64() + i * Marshal.SizeOf(typeof(hostfxr_dotnet_environment_sdk_info)));
var pointer = new IntPtr(infoStruct.sdks.ToInt64() + i * Marshal.SizeOf<hostfxr_dotnet_environment_sdk_info>());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

sdks[i] = Marshal.PtrToStructure<hostfxr_dotnet_environment_sdk_info>(pointer);
}
SdkInfo = sdks.Select(sdk => new NetSdkInfo(sdk.version, sdk.path));
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<SDKCustomXUnitProject Include="**\*.Tests.csproj" Exclude="**\*.AoT.Tests.csproj;TestAssets\**\*.Tests.csproj;**\*.AnalyzerRedirecting.Tests.csproj" />
<SDKCustomXUnitProject Include="**\*.Tests.csproj" Exclude="**\*.AoT.Tests.csproj;TestAssets\**\*.Tests.csproj;**\*.AnalyzerRedirecting.Tests.csproj;**\dnup.Tests.csproj" />
<SDKCustomXUnitProject Include="$(RepoRoot)src\Microsoft.CodeAnalysis.NetAnalyzers\tests\**\*.*Tests.csproj" />
<SDKCustomXUnitProject Condition="$(_AGENTOSNAME) == 'Windows_NT_FullFramework'" Include="**\*.AnalyzerRedirecting.Tests.csproj">
<TargetFramework>net472</TargetFramework>
Expand Down
20 changes: 20 additions & 0 deletions test/dnup.Tests/LibraryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public LibraryTests(ITestOutputHelper log)
[Theory]
[InlineData("9")]
[InlineData("latest")]
[InlineData("sts")]
[InlineData("lts")]
[InlineData("preview")]
public void LatestVersionForChannelCanBeInstalled(string channel)
{
var releaseInfoProvider = InstallerFactory.CreateReleaseInfoProvider();
Expand All @@ -40,4 +43,21 @@ public void LatestVersionForChannelCanBeInstalled(string channel)
InstallComponent.SDK,
latestVersion!);
}

[Fact]
public void TestGetSupportedChannels()
{
var releaseInfoProvider = InstallerFactory.CreateReleaseInfoProvider();
var channels = releaseInfoProvider.GetSupportedChannels();

channels.Should().Contain(new[] { "latest", "lts", "sts", "preview" });

// This will need to be updated every few years as versions go out of support
channels.Should().Contain(new[] { "10.0", "10.0.1xx" });
channels.Should().NotContain("10");

channels.Should().NotContain("7.0");
channels.Should().NotContain("7.0.1xx");

}
}