Skip to content
Open
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
10 changes: 8 additions & 2 deletions src/Cli/dotnet/Commands/Sdk/Check/ProductCollectionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ public IEnumerable<ProductRelease> GetProductReleases(Deployment.DotNet.Releases
{
return product.GetReleasesAsync().Result;
}
catch (Exception e)
catch (Exception ex) when (ex is HttpRequestException ||
ex is FileNotFoundException ||
ex is AggregateException aggregateEx &&
(aggregateEx.InnerException is HttpRequestException ||
aggregateEx.InnerException is FileNotFoundException))
{
throw new GracefulException(string.Format(CliCommandStrings.ReleasesLibraryFailed, e.Message));
// Return empty collection if releases are not available (e.g., unreleased preview versions)
// This handles cases where the releases.json file doesn't exist yet for a version
return Enumerable.Empty<ProductRelease>();
}
}
}
27 changes: 23 additions & 4 deletions src/Cli/dotnet/Commands/Sdk/Check/SdkOutputWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ private bool NewerSdkPatchExists(NetSdkInfo bundle)

private ReleaseVersion? NewestSdkPatchVersion(NetSdkInfo bundle)
{
var product = _productCollection.First(product => product.ProductVersion.Equals($"{bundle.Version.Major}.{bundle.Version.Minor}"));
var product = _productCollection.FirstOrDefault(product => product.ProductVersion.Equals($"{bundle.Version.Major}.{bundle.Version.Minor}"));
if (product == null)
{
// No release information available for this SDK version
return null;
}

if (product.LatestSdkVersion.SdkFeatureBand == bundle.Version.SdkFeatureBand)
{
// This is the latest feature band
Expand All @@ -88,11 +94,24 @@ private bool NewerSdkPatchExists(NetSdkInfo bundle)

private bool NewFeatureBandAvailable()
{
return NewestFeatureBandAvailable() > _sdkInfo.Select(sdk => sdk.Version).Max();
if (!_sdkInfo.Any())
{
return false;
}

var newestAvailable = NewestFeatureBandAvailable();
return newestAvailable != null && newestAvailable > _sdkInfo.Select(sdk => sdk.Version).Max();
}

private ReleaseVersion NewestFeatureBandAvailable()
private ReleaseVersion? NewestFeatureBandAvailable()
{
return _productCollection.OrderByDescending(product => product.ProductVersion).First().LatestSdkVersion;
var newestProduct = _productCollection.OrderByDescending(product => product.ProductVersion).FirstOrDefault();
if (newestProduct != null)
{
return newestProduct.LatestSdkVersion;
}

// Fallback to the newest installed SDK if no product collection is available
return _sdkInfo.Any() ? _sdkInfo.Select(sdk => sdk.Version).Max() : null;
}
}
26 changes: 26 additions & 0 deletions test/dotnet.Tests/CommandTests/Sdk/Check/GivenDotnetSdkCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,32 @@ public void ItUsesConfigFile()
_reporter.Lines.Should().Contain(replacementString);
}

[Fact]
public void WhenSdkHasNoReleasesJsonItShowsVersionCheckUnavailable()
{
var parseResult = Parser.Parse(new string[] { "dotnet", "sdk", "check" });
// Install SDK 99.0.100 which doesn't have releases.json in the test assets
var bundles = GetFakeEnvironmentInfo(new[] { "3.1.100", "5.0.100", "99.0.100" }, new[] { "3.1.0", "5.0.0" });

// This should not throw even though 99.0 doesn't have releases.json
new SdkCheckCommand(parseResult, new MockNETBundleProvider(bundles), new MockProductCollectionProvider(fakeReleasesPath), _reporter).Execute();

// Verify all SDKs are shown
foreach (var version in bundles.SdkInfo.Select(b => b.Version.ToString()))
{
string.Join(' ', _reporter.Lines)
.Should()
.Contain(version);
}

// The SDK without releases should show version check failure
string.Join(' ', _reporter.Lines)
.Should()
.Contain("99.0.100")
.And
.Contain(CliCommandStrings.VersionCheckFailure);
}

private NetEnvironmentInfo GetFakeEnvironmentInfo(IEnumerable<string> sdkVersions, IEnumerable<string> runtimeVersions)
{
var sdks = sdkVersions.Select(version => new NetSdkInfo(version, string.Empty));
Expand Down