Skip to content

Commit 3fb1da0

Browse files
committed
Improve logging for #3
1 parent 9f6a313 commit 3fb1da0

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

src/AspireManifestGen.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
<Reference Include="System.ComponentModel.Composition" />
8787
</ItemGroup>
8888
<ItemGroup>
89+
<PackageReference Include="CliWrap">
90+
<Version>3.6.4</Version>
91+
</PackageReference>
8992
<PackageReference Include="Community.VisualStudio.VSCT" Version="16.0.29.6" PrivateAssets="all" />
9093
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.507" ExcludeAssets="Runtime">
9194
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/Commands/ManifestGen.cs

+23-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using AspireManifestGen.Options;
2+
using CliWrap;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.IO;
56
using System.Linq;
7+
using System.Text;
68

79
namespace AspireManifestGen;
810

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

1719
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e, Project project)
1820
{
19-
//var project = await VS.Solutions.GetActiveProjectAsync();
21+
var stdOutBuffer = new StringBuilder();
22+
var stdErrBuffer = new StringBuilder();
23+
OutputWindowPane pane = await VS.Windows.GetOutputWindowPaneAsync(Community.VisualStudio.Toolkit.Windows.VSOutputWindowPane.General);
24+
2025
var projectPath = Path.GetDirectoryName(project.FullPath);
2126

2227
var options = await General.GetLiveInstanceAsync();
2328

24-
var manifestPath = string.Empty;
25-
29+
string manifestPath;
2630
if (options.UseTempFile)
2731
{
2832
// get temp path to a file and rename the file extension to .json extension
@@ -35,26 +39,27 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e, Project projec
3539

3640
await VS.StatusBar.StartAnimationAsync(StatusAnimation.Build);
3741
await VS.StatusBar.ShowProgressAsync("Generating Aspire Manifest", 1, 2);
38-
Process process = new Process();
39-
process.StartInfo.WorkingDirectory = projectPath;
40-
process.StartInfo.FileName = "dotnet.exe";
41-
process.StartInfo.Arguments = $"msbuild /t:GenerateAspireManifest /p:AspireManifestPublishOutputPath={manifestPath}";
42-
process.StartInfo.UseShellExecute = false;
43-
process.StartInfo.RedirectStandardOutput = true;
44-
process.StartInfo.RedirectStandardError = true;
45-
process.StartInfo.CreateNoWindow = true;
46-
process.OutputDataReceived += (sender, args) => Debug.WriteLine(args.Data);
47-
process.ErrorDataReceived += (sender, args) => Debug.WriteLine(args.Data);
48-
process.Start();
49-
process.WaitForExit();
42+
43+
var result = await Cli.Wrap("dotnet")
44+
.WithArguments($"msbuild /t:GenerateAspireManifest /p:AspireManifestPublishOutputPath={manifestPath}")
45+
.WithWorkingDirectory(projectPath)
46+
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer))
47+
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer))
48+
.WithValidation(CommandResultValidation.None)
49+
.ExecuteAsync();
50+
51+
var stdErr = stdErrBuffer.ToString();
5052

5153
// TODO: Need better error handling, issue #3
52-
if (process.ExitCode != 0)
54+
if (result.ExitCode != 0)
5355
{
54-
var errorString = await process.StandardError.ReadToEndAsync();
55-
Debug.WriteLine($"Error: {errorString}");
56+
await pane.WriteLineAsync($"[.NET Aspire]: Unable to create manifest:{stdErr}:{result.ExitCode}");
5657
goto Cleanup;
5758
}
59+
else
60+
{
61+
await pane.WriteLineAsync($"[.NET Aspire]: Manifest created at {manifestPath}");
62+
}
5863

5964
await VS.Documents.OpenAsync(manifestPath);
6065

0 commit comments

Comments
 (0)