NATIVE_DLL_SEARCH_DIRECTORIES does not include NuGet runtime folders in LINQPad 8 & 9

Options

Hi Joe & team,

I’ve encountered a difference in behaviour between regular .NET applications (built with dotnet or Visual Studio) and LINQPad (both 8 and 9) regarding native-library probing paths.
This difference prevents libraries such as Silk.NET.Windowing, OpenTK, OpenCvSharp, etc. from finding their native DLLs when a query is executed in LINQPad.

Repro

  1. Create a plain console project (VS / dotnet new console) targeting net9.0 and run the following:
Console.WriteLine(AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES"));

Without any extra packages the output is e.g.:

C:\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.6\;
  1. Add a package that contains native assets, e.g.
<PackageReference Include="Sdcb.OpenCvSharp4.mini.runtime.win-x64" Version="4.11.0.35" />

Run again and you now get:

C:\Users\<user>\source\repos\ConsoleApp\ConsoleApp\bin\Debug\net9.0\runtimes\win-x64\native\;
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.6\;

The runtime’s runtimes\win-x64\native folder was appended automatically, so P/Invoke resolves correctly.

  1. Do the same test in LINQPad (8 or 9):
// Install NuGet Package: Sdcb.OpenCvSharp4.mini.runtime.win-x64
AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES").Dump();

whether or not the same NuGet package is referenced, the result is always:

C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\9.0.6\;
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.6\;

The NuGet runtime folder is missing, therefore native libraries shipped inside packages cannot be located.