|
9 | 9 | using System.Threading.Tasks; |
10 | 10 | using ICSharpCode.CodeConverter.Common; |
11 | 11 | using ICSharpCode.CodeConverter.CSharp; |
| 12 | +using ICSharpCode.CodeConverter.DotNetTool.Util; |
12 | 13 | using ICSharpCode.CodeConverter.Util; |
13 | 14 | using ICSharpCode.CodeConverter.VB; |
14 | 15 | using Microsoft.CodeAnalysis; |
@@ -117,30 +118,13 @@ private async Task<string> GetCompilationErrorsAsync(MSBuildWorkspace workspace, |
117 | 118 |
|
118 | 119 | private async Task RunDotnetRestoreAsync(string path) |
119 | 120 | { |
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) |
140 | 124 | { |
141 | 125 | 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}"); |
144 | 128 | } |
145 | 129 | } |
146 | 130 | } |
|
0 commit comments