An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Hello @Rosenbohm, Mario ,
Thanks for your question.
You cannot specify a custom directory path directly inside the xxx.deps.json file. The .deps.json file acts strictly as a manifest. It tells the runtime what dependencies (and versions) your DLL requires, but it is not designed to tell the runtime where to look for them on your local drive. By default, the runtime will only probe the application base directory or the folder where the DLL resides.
However, since you want to maintain a clean architecture with a shared dependency folder, you can refer to some following workarounds.
- Using
additionalProbingPaths:
While you cannot set paths in the .deps.json file, you can use the [YourDllName].runtimeconfig.json file. You can add an additionalProbingPaths array to instruct the host to look in your shared directory.
Example in xxx.runtimeconfig.json:
{
"runtimeOptions": {
"additionalProbingPaths": ["C:\\Path\\To\\Your\\SharedDependencies"]
}
}
Note: Because a third-party exe is loading your DLLs, this approach heavily depends on how that exe initializes its host. Sometimes, host applications ignore the runtimeconfig.json of dynamically loaded plugins.
- Custom
AssemblyLoadContext.
For modern .NET (.NET Core / .NET 5+), I suggest loading plugins with shared dependencies is through code using AssemblyLoadContext paired with an AssemblyDependencyResolver.
Instead of relying on configuration files, you take control of the loading process:
- You create a custom
AssemblyLoadContext. - You use
AssemblyDependencyResolverto parse your DLL's.deps.jsonfile. - You override the
Loadmethod. When your plugin needs a dependency, your custom context intercepts the request and you explicitly tell it to load the DLL from your shared directory path usingLoadFromAssemblyPath().
I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.