1
1
using AspireManifestGen . Options ;
2
+ using CliWrap ;
2
3
using System . Collections . Generic ;
3
4
using System . Diagnostics ;
4
5
using System . IO ;
5
6
using System . Linq ;
7
+ using System . Text ;
6
8
7
9
namespace AspireManifestGen ;
8
10
@@ -16,13 +18,15 @@ protected override void BeforeQueryStatus(OleMenuCommand menuItem, EventArgs e,
16
18
17
19
protected override async Task ExecuteAsync ( OleMenuCmdEventArgs e , Project project )
18
20
{
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
+
20
25
var projectPath = Path . GetDirectoryName ( project . FullPath ) ;
21
26
22
27
var options = await General . GetLiveInstanceAsync ( ) ;
23
28
24
- var manifestPath = string . Empty ;
25
-
29
+ string manifestPath ;
26
30
if ( options . UseTempFile )
27
31
{
28
32
// 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
35
39
36
40
await VS . StatusBar . StartAnimationAsync ( StatusAnimation . Build ) ;
37
41
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 ( ) ;
50
52
51
53
// TODO: Need better error handling, issue #3
52
- if ( process . ExitCode != 0 )
54
+ if ( result . ExitCode != 0 )
53
55
{
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 } ") ;
56
57
goto Cleanup ;
57
58
}
59
+ else
60
+ {
61
+ await pane . WriteLineAsync ( $ "[.NET Aspire]: Manifest created at { manifestPath } ") ;
62
+ }
58
63
59
64
await VS . Documents . OpenAsync ( manifestPath ) ;
60
65
0 commit comments