diff --git a/src/Aspire.Cli/DotNet/DotNetCliRunner.cs b/src/Aspire.Cli/DotNet/DotNetCliRunner.cs index 0d2a1b833a9..b3247b6c6c5 100644 --- a/src/Aspire.Cli/DotNet/DotNetCliRunner.cs +++ b/src/Aspire.Cli/DotNet/DotNetCliRunner.cs @@ -649,7 +649,7 @@ public async Task TrustHttpCertificateAsync(DotNetCliRunnerInvocationOption } } - private static bool TryParsePackageVersionFromStdout(string stdout, [NotNullWhen(true)] out string? version) + internal static bool TryParsePackageVersionFromStdout(string stdout, [NotNullWhen(true)] out string? version) { var lines = stdout.Split(Environment.NewLine); var successLine = lines.SingleOrDefault(x => x.StartsWith("Success: Aspire.ProjectTemplates")); @@ -661,9 +661,12 @@ private static bool TryParsePackageVersionFromStdout(string stdout, [NotNullWhen } var templateVersion = successLine.Split(" ") switch { // Break up the success line. - { Length: > 2 } chunks => chunks[1].Split("::") switch { // Break up the template+version string + { Length: > 2 } chunks => chunks[1].Split("@") switch { // Break up the template+version string (@ separator for .NET 10.0+) { Length: 2 } versionChunks => versionChunks[1], // The version in the second chunk - _ => null + _ => chunks[1].Split("::") switch { // Fallback to :: separator for older SDK versions + { Length: 2 } versionChunks => versionChunks[1], + _ => null + } }, _ => null }; diff --git a/tests/Aspire.Cli.Tests/DotNet/DotNetCliRunnerTests.cs b/tests/Aspire.Cli.Tests/DotNet/DotNetCliRunnerTests.cs index 98fc52b4c5e..dd27c7c5041 100644 --- a/tests/Aspire.Cli.Tests/DotNet/DotNetCliRunnerTests.cs +++ b/tests/Aspire.Cli.Tests/DotNet/DotNetCliRunnerTests.cs @@ -1192,4 +1192,19 @@ public async Task SearchPackagesAsyncSucceedsOnFirstAttemptWithoutRetry() Assert.NotNull(result.Packages); Assert.Equal(1, executor.AttemptCount); // Should have attempted only once } + + [Theory] + [InlineData("Success: Aspire.ProjectTemplates@13.2.0-preview.1.26101.12 installed the following templates:", true, "13.2.0-preview.1.26101.12")] // New .NET 10.0 SDK format with @ separator + [InlineData("Success: Aspire.ProjectTemplates::13.2.0-preview.1.26101.12 installed the following templates:", true, "13.2.0-preview.1.26101.12")] // Old SDK format with :: separator + [InlineData("Some other output", false, null)] // Missing success line + [InlineData("Success: Aspire.ProjectTemplates installed the following templates:", false, null)] // Invalid format without version separator + public void TryParsePackageVersionFromStdout_ParsesCorrectly(string stdout, bool expectedResult, string? expectedVersion) + { + // Act + var result = DotNetCliRunner.TryParsePackageVersionFromStdout(stdout, out var version); + + // Assert + Assert.Equal(expectedResult, result); + Assert.Equal(expectedVersion, version); + } }