Another way. Not tested with PowerShell dlls.
It will not copy dlls to the exe folder, but will use dlls in the PowerShell folder.
using System.Runtime.Loader;
AssemblyLoadContext.Default.Resolving += (o, e) => {
//print.it(e.Name);
var path = $@"C:\Program Files\PowerShell\7\{e.Name}.dll";
if (filesystem.exists(path)) return AssemblyLoadContext.Default.LoadFromAssemblyPath(path);
return null;
};
It will not copy dlls to the exe folder, but will use dlls in the PowerShell folder.