diff --git a/src/Microsoft.Tye.Core/ProcessUtil.cs b/src/Microsoft.Tye.Core/ProcessUtil.cs index 103ea3a6..60d9a133 100644 --- a/src/Microsoft.Tye.Core/ProcessUtil.cs +++ b/src/Microsoft.Tye.Core/ProcessUtil.cs @@ -144,7 +144,8 @@ namespace Microsoft.Tye { try { - Process.GetProcessById(pid)?.Kill(); + using var process = Process.GetProcessById(pid); + process?.Kill(); } catch (ArgumentException) { } catch (InvalidOperationException) { } diff --git a/src/Microsoft.Tye.Hosting/ProcessRunner.cs b/src/Microsoft.Tye.Hosting/ProcessRunner.cs index 6ad4accb..3238ae51 100644 --- a/src/Microsoft.Tye.Hosting/ProcessRunner.cs +++ b/src/Microsoft.Tye.Hosting/ProcessRunner.cs @@ -332,8 +332,8 @@ namespace Microsoft.Tye.Hosting private static string? GetDotnetRoot() { - var process = Process.GetCurrentProcess(); - var entryPointFilePath = process.MainModule.FileName; + var entryPointFilePath = GetEntryPointFilePath(); + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Path.GetFileNameWithoutExtension(entryPointFilePath) == "dotnet") { @@ -347,6 +347,12 @@ namespace Microsoft.Tye.Hosting return null; } + private static string GetEntryPointFilePath() + { + using var process = Process.GetCurrentProcess(); + return process.MainModule.FileName; + } + private class ProcessInfo {