add Process2
This commit is contained in:
9
nuget.config
Normal file
9
nuget.config
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
|
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
|
||||||
|
<clear />
|
||||||
|
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
|
||||||
|
<add key="localnugettest" value="C:\Users\Matthew\AppData\Roaming\LocalNuget" />
|
||||||
|
</packageSources>
|
||||||
|
</configuration>
|
||||||
@@ -1,45 +1,47 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Ardalis.GuardClauses;
|
using Ardalis.GuardClauses;
|
||||||
|
using AsyncReadProcess.Common;
|
||||||
|
using AsyncReadProcess;
|
||||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||||
|
|
||||||
namespace SharpIDE.Application.Features.Run;
|
namespace SharpIDE.Application.Features.Run;
|
||||||
|
|
||||||
public class RunService
|
public class RunService
|
||||||
{
|
{
|
||||||
|
public HashSet<SharpIdeProjectModel> RunningProjects { get; } = [];
|
||||||
// TODO: optimise this Copilot junk
|
// TODO: optimise this Copilot junk
|
||||||
public async Task RunProject(SharpIdeProjectModel project)
|
public async Task RunProject(SharpIdeProjectModel project)
|
||||||
{
|
{
|
||||||
Guard.Against.Null(project, nameof(project));
|
Guard.Against.Null(project, nameof(project));
|
||||||
Guard.Against.NullOrWhiteSpace(project.FilePath, nameof(project.FilePath), "Project file path cannot be null or empty.");
|
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",
|
FileName = "dotnet",
|
||||||
Arguments = $"run --project \"{project.FilePath}\"",
|
Arguments = $"run --project \"{project.FilePath}\" --no-build",
|
||||||
UseShellExecute = false,
|
|
||||||
CreateNoWindow = true,
|
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
RedirectStandardError = true
|
RedirectStandardError = true
|
||||||
};
|
};
|
||||||
|
|
||||||
using var process = new Process();
|
await using var process = new AsyncReadProcess.Process2()
|
||||||
process.StartInfo = processStartInfo;
|
{
|
||||||
|
StartInfo = processStartInfo
|
||||||
process.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
|
};
|
||||||
process.ErrorDataReceived += (sender, e) => Console.Error.WriteLine(e.Data);
|
|
||||||
|
|
||||||
process.Start();
|
process.Start();
|
||||||
|
|
||||||
process.BeginOutputReadLine();
|
_ = Task.Run(async () =>
|
||||||
process.BeginErrorReadLine();
|
{
|
||||||
|
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();
|
await process.WaitForExitAsync();
|
||||||
|
|
||||||
if (process.ExitCode != 0)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException($"Project run failed with exit code {process.ExitCode}.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("Project ran successfully.");
|
Console.WriteLine("Project ran successfully.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- If any Microsoft.Build.dll ends up in the output, it will be prioritised for loading by MSBuild Nodes -->
|
<!-- If any Microsoft.Build.dll ends up in the output, it will be prioritised for loading by MSBuild Nodes -->
|
||||||
<PackageReference Include="Ardalis.GuardClauses" Version="5.0.0" />
|
<PackageReference Include="Ardalis.GuardClauses" Version="5.0.0" />
|
||||||
|
<PackageReference Include="AsyncReadProcess" Version="1.0.0-preview4" />
|
||||||
<PackageReference Include="Microsoft.Build" Version="17.14.8" ExcludeAssets="runtime" />
|
<PackageReference Include="Microsoft.Build" Version="17.14.8" ExcludeAssets="runtime" />
|
||||||
<PackageReference Include="Microsoft.Build.Framework" Version="17.14.8" ExcludeAssets="runtime" />
|
<PackageReference Include="Microsoft.Build.Framework" Version="17.14.8" ExcludeAssets="runtime" />
|
||||||
<PackageReference Include="Microsoft.Build.Locator" Version="1.9.1" />
|
<PackageReference Include="Microsoft.Build.Locator" Version="1.9.1" />
|
||||||
|
|||||||
Reference in New Issue
Block a user