-
Notifications
You must be signed in to change notification settings - Fork 876
Expand file tree
/
Copy pathAppHostHelper.cs
More file actions
75 lines (63 loc) · 3.41 KB
/
AppHostHelper.cs
File metadata and controls
75 lines (63 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Semver;
using Spectre.Console;
using System.Diagnostics;
namespace Aspire.Cli.Utils;
internal static class AppHostHelper
{
private static readonly ActivitySource s_activitySource = new ActivitySource(nameof(AppHostHelper));
internal static async Task<(bool IsCompatableAppHost, bool SupportsBackchannel)> CheckAppHostCompatabilityAsync(DotNetCliRunner runner, FileInfo projectFile, CancellationToken cancellationToken)
{
var appHostInformation = await GetAppHostInformationAsync(runner, projectFile, cancellationToken);
if (appHostInformation.ExitCode != 0)
{
AnsiConsole.MarkupLine($"[red bold]:thumbs_down: The project could not be analyzed due to a build error. For more information run with --debug switch.[/]");
return (false, false);
}
if (!appHostInformation.IsAspireHost)
{
AnsiConsole.MarkupLine($"[red bold]:thumbs_down: The project is not an Aspire app host project.[/]");
return (false, false);
}
if (!SemVersion.TryParse(appHostInformation.AspireHostingSdkVersion, out var aspireSdkVersion))
{
AnsiConsole.MarkupLine($"[red bold]:thumbs_down: Could not parse Aspire SDK version.[/]");
return (false, false);
}
var compatibleRanges = SemVersionRange.Parse("^9.2.0-dev", SemVersionRangeOptions.IncludeAllPrerelease);
if (!aspireSdkVersion.Satisfies(compatibleRanges))
{
AnsiConsole.MarkupLine($"[red bold]:thumbs_down: The Aspire SDK version '{appHostInformation.AspireHostingSdkVersion}' is not supported. Please update to the latest version.[/]");
return (false, false);
}
else
{
// NOTE: When we go to support < 9.2.0 app hosts this is where we'll make
// a determination as to whether the apphsot supports backchannel or not.
return (true, true);
}
}
internal static async Task<(int ExitCode, bool IsAspireHost, string? AspireHostingSdkVersion)> GetAppHostInformationAsync(DotNetCliRunner runner, FileInfo projectFile, CancellationToken cancellationToken)
{
using var activity = s_activitySource.StartActivity(nameof(GetAppHostInformationAsync), ActivityKind.Client);
var appHostInformationResult = await AnsiConsole.Status()
.Spinner(Spinner.Known.Dots3)
.SpinnerStyle(Style.Parse("purple"))
.StartAsync(
":microscope: Checking project type...",
async (context) => {
return await runner.GetAppHostInformationAsync(projectFile, cancellationToken);
});
return appHostInformationResult;
}
internal static async Task<int> BuildAppHostAsync(DotNetCliRunner runner, FileInfo projectFile, CancellationToken cancellationToken)
{
return await AnsiConsole.Status()
.Spinner(Spinner.Known.Dots3)
.SpinnerStyle(Style.Parse("purple"))
.StartAsync(":hammer_and_wrench: Building app host...", async context => {
return await runner.BuildAsync(projectFile, cancellationToken).ConfigureAwait(false);
});
}
}