Skip to content

Commit 26ace3d

Browse files
Use existing process runner
1 parent c25dc44 commit 26ace3d

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

CommandLine/CodeConv.Shared/MSBuildWorkspaceConverter.cs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Threading.Tasks;
1010
using ICSharpCode.CodeConverter.Common;
1111
using ICSharpCode.CodeConverter.CSharp;
12+
using ICSharpCode.CodeConverter.DotNetTool.Util;
1213
using ICSharpCode.CodeConverter.Util;
1314
using ICSharpCode.CodeConverter.VB;
1415
using Microsoft.CodeAnalysis;
@@ -117,30 +118,13 @@ private async Task<string> GetCompilationErrorsAsync(MSBuildWorkspace workspace,
117118

118119
private async Task RunDotnetRestoreAsync(string path)
119120
{
120-
var processStartInfo = new ProcessStartInfo
121-
{
122-
FileName = "dotnet",
123-
Arguments = $"restore \"{path}\"",
124-
RedirectStandardOutput = true,
125-
RedirectStandardError = true,
126-
UseShellExecute = false,
127-
CreateNoWindow = true
128-
};
129-
130-
using var process = new Process { StartInfo = processStartInfo };
131-
var output = new StringBuilder();
132-
var error = new StringBuilder();
133-
process.OutputDataReceived += (sender, args) => { if (args.Data != null) output.AppendLine(args.Data); };
134-
process.ErrorDataReceived += (sender, args) => { if (args.Data != null) error.AppendLine(args.Data); };
135-
process.Start();
136-
process.BeginOutputReadLine();
137-
process.BeginErrorReadLine();
138-
await process.WaitForExitAsync();
139-
if (process.ExitCode != 0)
121+
var psi = new ProcessStartInfo("dotnet", $"restore \"{path}\"");
122+
var (exitCode, _, stdErr) = await psi.GetOutputAsync();
123+
if (exitCode != 0)
140124
{
141125
throw new InvalidOperationException(
142-
$"dotnet restore failed with exit code {process.ExitCode}.\n" +
143-
$"Error: {error}");
126+
$"dotnet restore failed with exit code {exitCode}.\n" +
127+
$"Error: {stdErr}");
144128
}
145129
}
146130
}

0 commit comments

Comments
 (0)