Skip to content
Merged
31 changes: 25 additions & 6 deletions src/Aspire.Cli/Commands/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public NewCommand(

// Customize description based on whether staging channel is enabled
var isStagingEnabled = KnownFeatures.IsStagingChannelEnabled(_features, configuration)
|| string.Equals(ExecutionContext.IdentityChannel, PackageChannelNames.Staging, StringComparison.OrdinalIgnoreCase);
|| string.Equals(ExecutionContext.IdentityChannel, PackageChannelNames.Staging, StringComparisons.ChannelName);
_channelOption = new Option<string?>("--channel")
{
Description = isStagingEnabled
Expand Down Expand Up @@ -333,20 +333,39 @@ private async Task<ResolveTemplateVersionResult> ResolveCliTemplateVersionAsync(
!string.IsNullOrWhiteSpace(ExecutionContext.IdentityChannel))
{
identityChannelMatch = channels.FirstOrDefault(c =>
string.Equals(c.Name, ExecutionContext.IdentityChannel, StringComparison.OrdinalIgnoreCase));
string.Equals(c.Name, ExecutionContext.IdentityChannel, StringComparisons.ChannelName));
}

var selectedChannel = string.IsNullOrWhiteSpace(configuredChannelName)
? identityChannelMatch
?? channels.FirstOrDefault(c => c.Type is PackageChannelType.Implicit)
?? channels.FirstOrDefault()
: channels.FirstOrDefault(c => string.Equals(c.Name, configuredChannelName, StringComparison.OrdinalIgnoreCase));
: channels.FirstOrDefault(c => string.Equals(c.Name, configuredChannelName, StringComparisons.ChannelName));

if (selectedChannel is null)
{
var errorMessage = string.IsNullOrWhiteSpace(configuredChannelName)
? "No package channels are available."
: $"No channel found matching '{configuredChannelName}'. Valid options are: {string.Join(", ", channels.Select(c => c.Name))}";
string errorMessage;
if (string.IsNullOrWhiteSpace(configuredChannelName))
{
errorMessage = NewCommandStrings.NoPackageChannelsAvailable;
}
else if (string.Equals(configuredChannelName, PackageChannelNames.Staging, StringComparisons.ChannelName)
&& _packagingService.GetStagingChannelUnavailableReason() is { } stagingReason)
{
// Surface the actionable packaging-service reason (e.g. "daily CLI cannot
// synthesize a staging channel; set overrideStagingFeed") instead of the
// generic channel list, mirroring UpdateCommand's behavior.
// See https://github.com/microsoft/aspire/issues/16652.
errorMessage = stagingReason;
}
else
{
errorMessage = string.Format(
CultureInfo.CurrentCulture,
NewCommandStrings.NoChannelFoundMatching,
configuredChannelName,
string.Join(", ", channels.Select(c => c.Name)));
}
Comment thread
mitchdenny marked this conversation as resolved.

return new ResolveTemplateVersionResult { ErrorMessage = errorMessage };
}
Expand Down
33 changes: 28 additions & 5 deletions src/Aspire.Cli/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,31 @@ protected override async Task<CommandResult> ExecuteAsync(ParseResult parseResul
if (!string.IsNullOrWhiteSpace(channelName))
{
// Try to find a channel matching the provided channel/quality
channel = allChannels.FirstOrDefault(c => string.Equals(c.Name, channelName, StringComparison.OrdinalIgnoreCase))
?? throw new ChannelNotFoundException($"No channel found matching '{channelName}'. Valid options are: {string.Join(", ", allChannels.Select(c => c.Name))}");
var matchedChannel = allChannels.FirstOrDefault(c => string.Equals(c.Name, channelName, StringComparisons.ChannelName));
if (matchedChannel is null)
{
// When the user explicitly asked for the 'staging' channel and the packaging
// service refused to synthesize it (daily/local/pr-N CLI without an override),
// surface the packaging-service reason instead of the generic "no channel
// matching" message — the generic message hides the actual fix from the user.
// See https://github.com/microsoft/aspire/issues/16652.
if (string.Equals(channelName, PackageChannelNames.Staging, StringComparisons.ChannelName))
{
var stagingUnavailableReason = _packagingService.GetStagingChannelUnavailableReason();
if (stagingUnavailableReason is not null)
{
throw new ChannelNotFoundException(stagingUnavailableReason);
}
}

throw new ChannelNotFoundException(string.Format(
CultureInfo.CurrentCulture,
UpdateCommandStrings.NoChannelFoundMatching,
channelName,
string.Join(", ", allChannels.Select(c => c.Name))));
}

channel = matchedChannel;

if (channelFromConfig)
{
Expand Down Expand Up @@ -240,9 +263,9 @@ protected override async Task<CommandResult> ExecuteAsync(ParseResult parseResul
var identityChannel = ExecutionContext.IdentityChannel;
PackageChannel? identityMatch = null;
if (!string.IsNullOrWhiteSpace(identityChannel)
&& !string.Equals(identityChannel, PackageChannelNames.Local, StringComparison.OrdinalIgnoreCase))
&& !string.Equals(identityChannel, PackageChannelNames.Local, StringComparisons.ChannelName))
{
identityMatch = allChannels.FirstOrDefault(c => string.Equals(c.Name, identityChannel, StringComparison.OrdinalIgnoreCase));
identityMatch = allChannels.FirstOrDefault(c => string.Equals(c.Name, identityChannel, StringComparisons.ChannelName));
}

if (identityMatch is not null)
Expand Down Expand Up @@ -362,7 +385,7 @@ protected override async Task<CommandResult> ExecuteAsync(ParseResult parseResul
private bool IsStagingChannelAvailable()
{
return KnownFeatures.IsStagingChannelEnabled(_features, _configuration)
|| string.Equals(ExecutionContext.IdentityChannel, PackageChannelNames.Staging, StringComparison.OrdinalIgnoreCase);
|| string.Equals(ExecutionContext.IdentityChannel, PackageChannelNames.Staging, StringComparisons.ChannelName);
}

private async Task<CommandResult> ExecuteSelfUpdateAsync(ParseResult parseResult, CancellationToken cancellationToken, string? selectedChannel = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Cli/KnownFeatures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ public static IEnumerable<string> GetAllFeatureNames()
public static bool IsStagingChannelEnabled(IFeatures features, IConfiguration configuration)
{
return features.IsFeatureEnabled(StagingChannelEnabled, false)
|| string.Equals(configuration["channel"], PackageChannelNames.Staging, StringComparison.OrdinalIgnoreCase);
|| string.Equals(configuration["channel"], PackageChannelNames.Staging, StringComparisons.ChannelName);
}
}
Loading
Loading