Skip to content

Commit

Permalink
Target .net 6 and later
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifAqqad committed May 25, 2024
1 parent 37effdb commit fb0b363
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 46 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# AspireRunner

A standalone runner for the .NET [Aspire Dashboard](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/standalone) which can be used to display OpenTelemetry
data (traces, metrics, and logs) from any application.
A standalone runner for the .NET [Aspire Dashboard](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/standalone) which can display OpenTelemetry data (traces,
metrics, and logs) from any application.

The runner can be used as a [dotnet tool](./src/AspireRunner.Tool/README.md) or as part of an [ASP.NET Core application](./src/AspireRunner.AspNetCore/README.md), it will automatically download the dashboard if it's not installed, and will run and manage the dashboard process.

> [!NOTE]
> Currently, the runner requires both the .NET 8 SDK and the [aspire workload](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/setup-tooling?tabs=dotnet-cli%2Cunix) to
> be installed.
>
> The runner will prioritize using the dashboard bundled with the [Aspire workload](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/setup-tooling?tabs=windows&pivots=visual-studio), if it's installed.
> [!IMPORTANT]
> While the runner itself targets .NET 6 (and later), the dashboard requires the .NET 8/9 runtime to run.
>
> Eventually (wip), it'll be able to automatically fetch and install the dashboard and therefore would only require the .NET runtime.
> Meaning that the runner can be used as part of a .NET 6 application, but you still need to have the .NET 8/9 runtime installed to run the dashboard.

## [AspireRunner.Tool](./src/AspireRunner.Tool/README.md)

Provides an easy to use dotnet tool for running the Dashboard
Provides an easy to use dotnet tool for downloading and running the Dashboard

[![NuGet Version](https://img.shields.io/nuget/vpre/AspireRunner.Tool?style=flat&logo=nuget&color=%230078d4&link=https%3A%2F%2Fwww.nuget.org%2Fpackages%2FAspireRunner.Tool)](https://www.nuget.org/packages/AspireRunner.Tool)

### Installation

```bash
# Install the aspire workload (skip if already installed)
dotnet workload install aspire

# Install the AspireRunner tool
dotnet tool install -g AspireRunner.Tool
```

Expand Down
3 changes: 1 addition & 2 deletions src/AspireRunner.Core/AspireDashboard.Regex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ namespace AspireRunner.Core;

public partial class AspireDashboard
{
[GeneratedRegex(@$"((?:{LoginConsoleMessage})|(?:{DashboardStartedConsoleMessage})) +(?<url>https?:\/\/[^\s]+)", RegexOptions.Compiled | RegexOptions.IgnoreCase)]
private static partial Regex LaunchUrlRegex();
private static readonly Regex LaunchUrlRegex = new(@$"((?:{LoginConsoleMessage})|(?:{DashboardStartedConsoleMessage})) +(?<url>https?:\/\/[^\s]+)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
}
2 changes: 1 addition & 1 deletion src/AspireRunner.Core/AspireDashboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private void OutputHandler(string output)
return;
}

if (LaunchUrlRegex().Match(output) is { Success: true } match)
if (LaunchUrlRegex.Match(output) is { Success: true } match)
{
var url = match.Groups["url"].Value;
if (_options.Runner.LaunchBrowser)
Expand Down
8 changes: 7 additions & 1 deletion src/AspireRunner.Core/AspireRunner.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

<PropertyGroup>
<Version>1.1.0</Version>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<langversion>latest</langversion>

<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down Expand Up @@ -36,4 +37,9 @@
<PackageReference Include="NuGet.Protocol" Version="6.9.1" />
<PackageReference Include="SemanticVersioning" Version="2.0.2"/>
</ItemGroup>

<ItemGroup Condition="('$(TargetFramework)'=='net6.0') Or ('$(TargetFramework)'=='net7.0') ">
<PackageReference Include="System.Text.Json" Version="8.0.3"/>
</ItemGroup>

</Project>
12 changes: 4 additions & 8 deletions src/AspireRunner.Core/Helpers/DotnetCli.Regex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ namespace AspireRunner.Core.Helpers;

public partial class DotnetCli
{
[GeneratedRegex(@"([\d\.]+)\s+(?:\[(.+)\])?", RegexOptions.Compiled)]
private static partial Regex SdkOutputRegex();
private static readonly Regex SdkOutputRegex = new(@"([\d\.]+)\s+(?:\[(.+)\])?", RegexOptions.Compiled);

[GeneratedRegex(@"(.+?) ([\d\-_.\w]+?) \[(.+)\]", RegexOptions.Compiled)]
private static partial Regex RuntimeOutputRegex();
private static readonly Regex RuntimeOutputRegex = new(@"(.+?) ([\d\-_.\w]+?) \[(.+)\]", RegexOptions.Compiled);

[GeneratedRegex(@"-+\r?\n([\w\W]+?)\r?\n\r?\n", RegexOptions.Compiled)]
private static partial Regex TableContentRegex();
private static readonly Regex TableContentRegex = new(@"-+\r?\n([\w\W]+?)\r?\n\r?\n", RegexOptions.Compiled);

[GeneratedRegex(@"\s{2,}", RegexOptions.Compiled)]
private static partial Regex TableColumnSeperatorRegex();
private static readonly Regex TableColumnSeperatorRegex = new(@"\s{2,}", RegexOptions.Compiled);
}
15 changes: 10 additions & 5 deletions src/AspireRunner.Core/Helpers/DotnetCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public string Run(string arguments)
/// <exception cref="InvalidOperationException">The dotnet CLI process failed to start.</exception>
public Process Run(string[] arguments, string? workingDirectory = null, IDictionary<string, string>? environement = null, Action<string>? outputHandler = null, Action<string>? errorHandler = null)
{
var processStartInfo = new ProcessStartInfo(Path.Combine(CliPath, Executable), arguments)
var processStartInfo = new ProcessStartInfo(Path.Combine(CliPath, Executable))
{
CreateNoWindow = true,
UseShellExecute = false,
Expand All @@ -85,6 +85,11 @@ public Process Run(string[] arguments, string? workingDirectory = null, IDiction
WindowStyle = ProcessWindowStyle.Hidden
};

foreach (var argument in arguments)
{
processStartInfo.ArgumentList.Add(argument);
}

if (environement != null)
{
foreach (var (key, value) in environement)
Expand Down Expand Up @@ -162,15 +167,15 @@ public string[] GetPacksFolders()
public string[] GetInstalledWorkloads()
{
var workloadsOutput = Run("workload list");
var workloadsMatch = TableContentRegex().Match(workloadsOutput);
var workloadsMatch = TableContentRegex.Match(workloadsOutput);
if (!workloadsMatch.Success)
{
return [];
}

return workloadsMatch.Value
.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries)
.Select(row => TableColumnSeperatorRegex().Split(row, 3)[0])
.Select(row => TableColumnSeperatorRegex.Split(row, 3)[0])
.Where(id => !string.IsNullOrWhiteSpace(id))
.ToArray();
}
Expand All @@ -188,7 +193,7 @@ public string[] GetInstalledWorkloads()
}

return runtimesOutput.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries)
.Select(s => RuntimeOutputRegex().Match(s))
.Select(s => RuntimeOutputRegex.Match(s))
.Where(m => m.Success)
.Select(m => (Name: m.Groups[1].Value, Version: new Version(m.Groups[2].Value)))
.ToArray();
Expand All @@ -202,7 +207,7 @@ public string[] GetInstalledWorkloads()
{
var sdksOutput = Run("--list-sdks");
var sdks = sdksOutput.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries)
.Select(s => SdkOutputRegex().Match(s))
.Select(s => SdkOutputRegex.Match(s))
.Where(m => m.Success)
.Select(m => (Version: m.Groups[1].Value, Path: m.Groups[2].Value))
.ToArray();
Expand Down
2 changes: 1 addition & 1 deletion src/AspireRunner.Core/Helpers/NugetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task<Version[]> GetPackageVersionsAsync(string packageName)
var resource = await _repository.GetResourceAsync<FindPackageByIdResource>();
var metadata = await resource.GetAllVersionsAsync(packageName, _cache, NullLogger.Instance, CancellationToken.None);

return metadata.Select(v => new Version(v.ToFullString(), true)).OrderDescending().ToArray();
return metadata.Select(v => new Version(v.ToFullString(), true)).OrderByDescending(v => v).ToArray();
}

public async Task<bool> DownloadPackageAsync(string packageName, Version version, string destinationPath)
Expand Down
3 changes: 2 additions & 1 deletion src/AspireRunner.Tool/AspireRunner.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<PropertyGroup>
<Version>1.1.0</Version>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<langversion>latest</langversion>

<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
38 changes: 22 additions & 16 deletions src/AspireRunner.Tool/README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
## AspireRunner
## AspireRunner.Tool

A dotnet tool for running the Aspire Dashboard that's bundled with the [aspire workload](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/setup-tooling?tabs=dotnet-cli%2Cunix).
A dotnet tool for downloading and running the standalone [Aspire Dashboard](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/standalone)

The dashboard can be used to display OpenTelemetry data (traces, metrics, and logs) from any application ([more info](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/overview))
The dashboard can display OpenTelemetry data (traces, metrics, and logs) from any application ([more info](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/overview)).

[![NuGet Version](https://img.shields.io/nuget/vpre/AspireRunner.Tool?style=flat&logo=nuget&color=%230078d4&link=https%3A%2F%2Fwww.nuget.org%2Fpackages%2FAspireRunner.Tool)](https://www.nuget.org/packages/AspireRunner.Tool)

## Installation

```bash
# Install the aspire workload (skip if already installed)
dotnet workload install aspire

# Install the AspireRunner tool
dotnet tool install -g AspireRunner.Tool
```

## Usage

```bash
```
aspire-dashboard <options>
Options:
-b, --browser Launch the dashboard in the default browser
-b, --browser Launch the dashboard in the default browser
-p, --port (Default: 18888) The port the dashboard will be available on
-p, --port (Default: 18888) The port the dashboard will be available on
-o, --otlp-port (Default: 4317) The port the OTLP server will listen on
-o, --otlp-port (Default: 4317) The port the OTLP server will listen on
-k, --otlp-key The API key to use for the OTLP server
-k, --otlp-key The API key to use for the OTLP server
-s, --https (Default: true) Use HTTPS instead of HTTP, this applies to both the dashboard and the OTLP server
-s, --https (Default: true) Use HTTPS instead of HTTP, this applies to both the dashboard and the OTLP server
-a, --auth Use browser token authentication for the dashboard
-a, --auth Use browser token authentication for the dashboard
-m, --multiple Allow running multiple instances of the dashboard, if this isn't passed, existing instances will be replaced
-m, --multiple Allow running multiple instances of the dashboard
-r, --runtime-version The version of the .NET runtime to use
--help Display this help screen.
-d, --auto-download (Default: true) Automatically download the dashboard if it's not installed
--version Display version information.
-v, --Verbose Enable verbose logging
--help Display this help screen.
--version Display version information.
```

> [!NOTE]
> The runner will prioritize using the dashboard bundled with the [Aspire workload](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/setup-tooling?tabs=windows&pivots=visual-studio), if it's installed.

0 comments on commit fb0b363

Please sign in to comment.