mirror of
https://github.com/Smaug123/WoofWare.DotnetRuntimeLocator
synced 2025-10-07 08:18:40 +00:00
Use PATH if possible (#5)
This commit is contained in:
@@ -8,12 +8,12 @@ module Program =
|
|||||||
let main argv =
|
let main argv =
|
||||||
let info = DotnetEnvironmentInfo.Get ()
|
let info = DotnetEnvironmentInfo.Get ()
|
||||||
Console.WriteLine info
|
Console.WriteLine info
|
||||||
Console.WriteLine ("SDKs:")
|
Console.WriteLine "SDKs:"
|
||||||
|
|
||||||
for sdk in info.Sdks do
|
for sdk in info.Sdks do
|
||||||
Console.WriteLine $"SDK: %O{sdk}"
|
Console.WriteLine $"SDK: %O{sdk}"
|
||||||
|
|
||||||
Console.WriteLine ("Frameworks:")
|
Console.WriteLine "Frameworks:"
|
||||||
|
|
||||||
for f in info.Frameworks do
|
for f in info.Frameworks do
|
||||||
Console.WriteLine $"Framework: %O{f}"
|
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>
|
/// <summary>
|
||||||
/// Get the environment information that is available to some arbitrary `dotnet` executable we were able to find.
|
/// Get the environment information that is available to some arbitrary `dotnet` executable we were able to find.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -171,14 +190,9 @@ public record DotnetEnvironmentInfo(
|
|||||||
/// <exception cref="Exception">Throws on any failure; handles nothing gracefully.</exception>
|
/// <exception cref="Exception">Throws on any failure; handles nothing gracefully.</exception>
|
||||||
public static DotnetEnvironmentInfo Get()
|
public static DotnetEnvironmentInfo Get()
|
||||||
{
|
{
|
||||||
var dotnetExe = FindDotnetAbove(new DirectoryInfo(RuntimeEnvironment.GetRuntimeDirectory()));
|
var dotnetExe = LocateDotnetExe();
|
||||||
|
|
||||||
if (ReferenceEquals(dotnetExe, null))
|
|
||||||
{
|
|
||||||
// This can happen! Maybe we're self-contained.
|
|
||||||
return GetSpecific(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// `null` can happen! Maybe we're self-contained.
|
||||||
return GetSpecific(dotnetExe);
|
return GetSpecific(dotnetExe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user