From 242defb3daf3bce084ae235435efcd62b2666511 Mon Sep 17 00:00:00 2001
From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com>
Date: Wed, 6 Aug 2025 01:56:49 +1000
Subject: [PATCH] add Process2
---
nuget.config | 9 +++++
.../Features/Run/RunService.cs | 34 ++++++++++---------
.../SharpIDE.Application.csproj | 1 +
3 files changed, 28 insertions(+), 16 deletions(-)
create mode 100644 nuget.config
diff --git a/nuget.config b/nuget.config
new file mode 100644
index 0000000..943860b
--- /dev/null
+++ b/nuget.config
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/SharpIDE.Application/Features/Run/RunService.cs b/src/SharpIDE.Application/Features/Run/RunService.cs
index 9baa7f8..56489db 100644
--- a/src/SharpIDE.Application/Features/Run/RunService.cs
+++ b/src/SharpIDE.Application/Features/Run/RunService.cs
@@ -1,45 +1,47 @@
using System.Diagnostics;
using Ardalis.GuardClauses;
+using AsyncReadProcess.Common;
+using AsyncReadProcess;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
namespace SharpIDE.Application.Features.Run;
public class RunService
{
+ public HashSet RunningProjects { get; } = [];
// TODO: optimise this Copilot junk
public async Task RunProject(SharpIdeProjectModel project)
{
Guard.Against.Null(project, nameof(project));
Guard.Against.NullOrWhiteSpace(project.FilePath, nameof(project.FilePath), "Project file path cannot be null or empty.");
- var processStartInfo = new ProcessStartInfo
+ var processStartInfo = new ProcessStartInfo2
{
FileName = "dotnet",
- Arguments = $"run --project \"{project.FilePath}\"",
- UseShellExecute = false,
- CreateNoWindow = true,
+ Arguments = $"run --project \"{project.FilePath}\" --no-build",
RedirectStandardOutput = true,
RedirectStandardError = true
};
- using var process = new Process();
- process.StartInfo = processStartInfo;
-
- process.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
- process.ErrorDataReceived += (sender, e) => Console.Error.WriteLine(e.Data);
+ await using var process = new AsyncReadProcess.Process2()
+ {
+ StartInfo = processStartInfo
+ };
process.Start();
- process.BeginOutputReadLine();
- process.BeginErrorReadLine();
+ _ = Task.Run(async () =>
+ {
+ await foreach(var log in process.CombinedOutputChannel.Reader.ReadAllAsync())
+ {
+ var logString = System.Text.Encoding.UTF8.GetString(log, 0, log.Length);
+ Console.Write(logString);
+ }
+ });
+
await process.WaitForExitAsync();
- if (process.ExitCode != 0)
- {
- throw new InvalidOperationException($"Project run failed with exit code {process.ExitCode}.");
- }
-
Console.WriteLine("Project ran successfully.");
}
}
diff --git a/src/SharpIDE.Application/SharpIDE.Application.csproj b/src/SharpIDE.Application/SharpIDE.Application.csproj
index fa8f089..4deb4f8 100644
--- a/src/SharpIDE.Application/SharpIDE.Application.csproj
+++ b/src/SharpIDE.Application/SharpIDE.Application.csproj
@@ -9,6 +9,7 @@
+