Skip to content

Commit

Permalink
Improve logging for #3
Browse files Browse the repository at this point in the history
  • Loading branch information
timheuer committed Dec 5, 2023
1 parent 9f6a313 commit 3fb1da0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/AspireManifestGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
<Reference Include="System.ComponentModel.Composition" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CliWrap">
<Version>3.6.4</Version>
</PackageReference>
<PackageReference Include="Community.VisualStudio.VSCT" Version="16.0.29.6" PrivateAssets="all" />
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.507" ExcludeAssets="Runtime">
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
41 changes: 23 additions & 18 deletions src/Commands/ManifestGen.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using AspireManifestGen.Options;
using CliWrap;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

namespace AspireManifestGen;

Expand All @@ -16,13 +18,15 @@ protected override void BeforeQueryStatus(OleMenuCommand menuItem, EventArgs e,

protected override async Task ExecuteAsync(OleMenuCmdEventArgs e, Project project)
{
//var project = await VS.Solutions.GetActiveProjectAsync();
var stdOutBuffer = new StringBuilder();
var stdErrBuffer = new StringBuilder();
OutputWindowPane pane = await VS.Windows.GetOutputWindowPaneAsync(Community.VisualStudio.Toolkit.Windows.VSOutputWindowPane.General);

var projectPath = Path.GetDirectoryName(project.FullPath);

var options = await General.GetLiveInstanceAsync();

var manifestPath = string.Empty;

string manifestPath;
if (options.UseTempFile)
{
// get temp path to a file and rename the file extension to .json extension
Expand All @@ -35,26 +39,27 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e, Project projec

await VS.StatusBar.StartAnimationAsync(StatusAnimation.Build);
await VS.StatusBar.ShowProgressAsync("Generating Aspire Manifest", 1, 2);
Process process = new Process();
process.StartInfo.WorkingDirectory = projectPath;
process.StartInfo.FileName = "dotnet.exe";
process.StartInfo.Arguments = $"msbuild /t:GenerateAspireManifest /p:AspireManifestPublishOutputPath={manifestPath}";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.OutputDataReceived += (sender, args) => Debug.WriteLine(args.Data);
process.ErrorDataReceived += (sender, args) => Debug.WriteLine(args.Data);
process.Start();
process.WaitForExit();

var result = await Cli.Wrap("dotnet")
.WithArguments($"msbuild /t:GenerateAspireManifest /p:AspireManifestPublishOutputPath={manifestPath}")
.WithWorkingDirectory(projectPath)
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer))
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer))
.WithValidation(CommandResultValidation.None)
.ExecuteAsync();

var stdErr = stdErrBuffer.ToString();

// TODO: Need better error handling, issue #3
if (process.ExitCode != 0)
if (result.ExitCode != 0)
{
var errorString = await process.StandardError.ReadToEndAsync();
Debug.WriteLine($"Error: {errorString}");
await pane.WriteLineAsync($"[.NET Aspire]: Unable to create manifest:{stdErr}:{result.ExitCode}");
goto Cleanup;
}
else
{
await pane.WriteLineAsync($"[.NET Aspire]: Manifest created at {manifestPath}");
}

await VS.Documents.OpenAsync(manifestPath);

Expand Down

0 comments on commit 3fb1da0

Please sign in to comment.