Hi. I need to specify IncludeAssets="build;compile" on one of my nuget package references. The DLL is resolved dynamically at runtime. Is this possible in LINQPad?
LINQPad doesn't use MSBuild and so ignores .props files and the build folder.
So is it not possible to achieve what I'm after? I can see in the assembly load context there is something called a 'ProbingSet' that has a link to the package version of the DLL. What is the 'ProbingSet', and can I manipulate it myself? I want a specific version of the DLL to be loaded (using an assembly resolver function) which lives in the installation directory of the application I'm trying to work with.
You can handle assembly resolution yourself as follows:
// LINQPad automatically calls the OnInit() method exactly once after the process has been created.
Util.AssemblyLoadContext.Resolving += (sender, args) =>
if (string.Equals (args.Name, "foo", StringComparison.OrdinalIgnoreCase))
return Util.AssemblyLoadContext.LoadFromAssemblyPath (".....");
Util.AssemblyLoadContext.ResolvingUnmanagedDll += (sender, args) => ...
The Resolving event fires after the default assembly resolution has failed. It will only fire, however, as a result of the runtime trying to resolve an assembly, or a call to an assembly loading method that loads an assembly by name. If you have code that attempts to load an assembly from a specific path, and that path doesn't exist, that call will still throw.
Another workaround is to publish a separate convention-based NuGet package for the benefit of LINQPad and other similar tools, with the assemblies in the expected places: