diff --git a/Example/Program.fs b/Example/Program.fs
index 26250a3..870afcd 100644
--- a/Example/Program.fs
+++ b/Example/Program.fs
@@ -8,12 +8,12 @@ module Program =
let main argv =
let info = DotnetEnvironmentInfo.Get ()
Console.WriteLine info
- Console.WriteLine ("SDKs:")
+ Console.WriteLine "SDKs:"
for sdk in info.Sdks do
Console.WriteLine $"SDK: %O{sdk}"
- Console.WriteLine ("Frameworks:")
+ Console.WriteLine "Frameworks:"
for f in info.Frameworks do
Console.WriteLine $"Framework: %O{f}"
diff --git a/WoofWare.DotnetRuntimeLocator/DotnetEnvironmentInfo.cs b/WoofWare.DotnetRuntimeLocator/DotnetEnvironmentInfo.cs
index b934e98..df0b751 100644
--- a/WoofWare.DotnetRuntimeLocator/DotnetEnvironmentInfo.cs
+++ b/WoofWare.DotnetRuntimeLocator/DotnetEnvironmentInfo.cs
@@ -164,6 +164,25 @@ public record DotnetEnvironmentInfo(
}
}
+ private static FileInfo? LocateDotnetExe()
+ {
+ var path = Environment.GetEnvironmentVariable("PATH");
+ if (path != null)
+ {
+ foreach (var component in path.Split(':'))
+ {
+ var dotnet = Path.Combine(component, "dotnet");
+ if (File.Exists(dotnet))
+ {
+ return new FileInfo(dotnet);
+ }
+ }
+ }
+
+ var renv = RuntimeEnvironment.GetRuntimeDirectory();
+ return FindDotnetAbove(new DirectoryInfo(renv));
+ }
+
///
/// Get the environment information that is available to some arbitrary `dotnet` executable we were able to find.
///
@@ -171,14 +190,9 @@ public record DotnetEnvironmentInfo(
/// Throws on any failure; handles nothing gracefully.
public static DotnetEnvironmentInfo Get()
{
- var dotnetExe = FindDotnetAbove(new DirectoryInfo(RuntimeEnvironment.GetRuntimeDirectory()));
-
- if (ReferenceEquals(dotnetExe, null))
- {
- // This can happen! Maybe we're self-contained.
- return GetSpecific(null);
- }
+ var dotnetExe = LocateDotnetExe();
+ // `null` can happen! Maybe we're self-contained.
return GetSpecific(dotnetExe);
}