diff --git a/src/AspireManifestGen.csproj b/src/AspireManifestGen.csproj index db8a605..f03e61b 100644 --- a/src/AspireManifestGen.csproj +++ b/src/AspireManifestGen.csproj @@ -47,6 +47,7 @@ + @@ -94,6 +95,9 @@ compile; build; native; contentfiles; analyzers; buildtransitive + + 8.0.0 + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/AspireManifestGenPackage.cs b/src/AspireManifestGenPackage.cs index cf259d2..f1c1a93 100644 --- a/src/AspireManifestGenPackage.cs +++ b/src/AspireManifestGenPackage.cs @@ -24,6 +24,7 @@ public sealed class AspireManifestGenPackage : ToolkitPackage protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) { + OutputWindowManager.AspireOutputPane = await VS.Windows.CreateOutputWindowPaneAsync(".NET Aspire", true); await this.RegisterCommandsAsync(); } } \ No newline at end of file diff --git a/src/Commands/InfraSynth.cs b/src/Commands/InfraSynth.cs index a3afbf7..df29cdd 100644 --- a/src/Commands/InfraSynth.cs +++ b/src/Commands/InfraSynth.cs @@ -1,5 +1,6 @@ using AspireManifestGen.Options; using CliWrap; +using Microsoft.Extensions.Logging; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -22,13 +23,14 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e, Project projec { var stdOutBuffer = new StringBuilder(); var stdErrBuffer = new StringBuilder(); - OutputWindowPane pane = await VS.Windows.GetOutputWindowPaneAsync(Community.VisualStudio.Toolkit.Windows.VSOutputWindowPane.General); + OutputWindowPane pane = OutputWindowManager.AspireOutputPane; var options = await General.GetLiveInstanceAsync(); var projectPath = FindAzureYaml(project.FullPath); await VS.StatusBar.StartAnimationAsync(StatusAnimation.Sync); await VS.StatusBar.ShowProgressAsync(STATUS_MESSAGE, 1, 2); + await pane.WriteLineAsync(OutputWindowManager.GenerateOutputMessage(STATUS_MESSAGE, "InfraSynth", LogLevel.Information)); var command = $"infra synth --force --no-prompt" + (options.AzdDebug ? " --debug" : ""); @@ -44,13 +46,13 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e, Project projec if (result.ExitCode != 0) { - await pane.WriteLineAsync($"[AZD]: Unable to synthesize infrastructure:{stdErr}:{result.ExitCode}"); + await pane.WriteLineAsync(OutputWindowManager.GenerateOutputMessage($"Unable to synthesize infrastructure:{stdErr}:{result.ExitCode}", "InfraSynth", LogLevel.Error)); goto Cleanup; } else { - await pane.WriteLineAsync($"[AZD]: infra synth completed"); - await pane.WriteLineAsync($"[AZD]: {stdOutBuffer}"); + await pane.WriteLineAsync(OutputWindowManager.GenerateOutputMessage($"Infra synth completed", "InfraSynth", LogLevel.Information)); + await pane.WriteLineAsync(OutputWindowManager.GenerateOutputMessage($"{stdOutBuffer}", "InfraSynth", LogLevel.Information)); } await VS.Documents.OpenAsync(Path.Combine(projectPath, "infra", "resources.bicep")); diff --git a/src/Commands/ManifestGen.cs b/src/Commands/ManifestGen.cs index 23371fd..57ccdbc 100644 --- a/src/Commands/ManifestGen.cs +++ b/src/Commands/ManifestGen.cs @@ -1,5 +1,6 @@ using AspireManifestGen.Options; using CliWrap; +using Microsoft.Extensions.Logging; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -22,7 +23,7 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e, Project projec { var stdOutBuffer = new StringBuilder(); var stdErrBuffer = new StringBuilder(); - OutputWindowPane pane = await VS.Windows.GetOutputWindowPaneAsync(Community.VisualStudio.Toolkit.Windows.VSOutputWindowPane.General); + OutputWindowPane pane = OutputWindowManager.AspireOutputPane; var projectPath = Path.GetDirectoryName(project.FullPath); @@ -41,6 +42,7 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e, Project projec await VS.StatusBar.StartAnimationAsync(StatusAnimation.Build); await VS.StatusBar.ShowProgressAsync(STATUS_MESSAGE, 1, 2); + await pane.WriteLineAsync(OutputWindowManager.GenerateOutputMessage(STATUS_MESSAGE, "ManifestGen", LogLevel.Information)); var result = await Cli.Wrap("dotnet") .WithArguments($"msbuild /t:GenerateAspireManifest /p:AspireManifestPublishOutputPath={manifestPath}") @@ -55,12 +57,12 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e, Project projec // TODO: Need better error handling, issue #3 if (result.ExitCode != 0) { - await pane.WriteLineAsync($"[.NET Aspire]: Unable to create manifest:{stdErr}:{result.ExitCode}"); + await pane.WriteLineAsync(OutputWindowManager.GenerateOutputMessage($"Unable to create manifest:{stdErr}:{result.ExitCode}", "ManifestGen", LogLevel.Error)); goto Cleanup; } else { - await pane.WriteLineAsync($"[.NET Aspire]: Manifest created at {manifestPath}"); + await pane.WriteLineAsync(OutputWindowManager.GenerateOutputMessage($"Manifest created at {manifestPath}", "ManifestGen", LogLevel.Information)); } await VS.Documents.OpenAsync(manifestPath); diff --git a/src/OutputWindowManager.cs b/src/OutputWindowManager.cs new file mode 100644 index 0000000..6b511dc --- /dev/null +++ b/src/OutputWindowManager.cs @@ -0,0 +1,12 @@ +using Microsoft.Extensions.Logging; + +public static class OutputWindowManager +{ + public static OutputWindowPane AspireOutputPane { get; set; } + + public static string GenerateOutputMessage(string message, string source, LogLevel logLevel) + { + var timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); + return $"[{logLevel.ToString().ToUpperInvariant()}] [{source.ToUpperInvariant()}] [{timestamp}]: {message}"; + } +}