mirror of
https://github.com/Smaug123/WoofWare.DotnetRuntimeLocator
synced 2025-10-05 07:18:40 +00:00
Use PATH if possible (#5)
This commit is contained in:
@@ -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}"
|
||||
|
@@ -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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the environment information that is available to some arbitrary `dotnet` executable we were able to find.
|
||||
/// </summary>
|
||||
@@ -171,14 +190,9 @@ public record DotnetEnvironmentInfo(
|
||||
/// <exception cref="Exception">Throws on any failure; handles nothing gracefully.</exception>
|
||||
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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user