Add runtime lookup (#94)

This commit is contained in:
Patrick Stevens
2025-05-16 20:25:40 +01:00
committed by GitHub
parent a013fc415e
commit 1b534018e9
13 changed files with 390 additions and 10 deletions

View File

@@ -3,7 +3,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<SelfContained>true</SelfContained>
</PropertyGroup>
<ItemGroup>

View File

@@ -1,6 +1,8 @@
namespace Example
namespace Example
open System
open System.IO
open System.Reflection
open WoofWare.DotnetRuntimeLocator
module Program =
@@ -18,4 +20,16 @@ module Program =
for f in info.Frameworks do
Console.WriteLine $"Framework: %O{f}"
// Identify the runtime which would execute this DLL
let self = Assembly.GetExecutingAssembly().Location
let runtimeSearchDirs = DotnetRuntime.SelectForDll self
// For example, the System.Text.Json.dll which this DLL would load:
runtimeSearchDirs
|> Seq.tryPick (fun dir ->
let attempt = Path.Combine (dir, "System.Text.Json.dll")
if File.Exists attempt then Some attempt else None
)
|> Option.get
|> fun s -> Console.WriteLine $"System.Text.Json location: %s{s}"
0