Mostly no, but a little bit yes. It depends :)
The build system (NuGet, the .NET SDK, msbuild) creates build output with all the dlls in one directory. If you need elasticsearch.dll
from two different versions of the package, how could this work? Obviously you can't have two files with a single name, so at least one would need to be renamed, but then when the CLR needs to load elasticsearch.dll
, how would it know that it has a different name, and how would it know what the new name is?
So, using the built-in functionality in the build system it's not possible.
However, the .NET Framework does support loading different versions of a dll, you just need to do work in copying files and to tell it where the different versions are. Using the codebase
element in an app.config file, you can tell it where the dlls are. You can see an example of this in use in %userprofile%\AppData\Local\Microsoft\VisualStudio\{your vs version folder}\devenv.exe.config
. The vast majority of this file is binding redirects and codeBase elements. You'll need more advanced build scripts that just running dotnet publish
to get all your dlls in the desired locations. It will probably prevent you from being able to start a debug session from VS, but you can always attach VS as a debugger to a running process, so it's still possible to debug, it's just harder.
This might be .NET Framework only. If it doesn't work on .NET Core, you can look into AssemblyLoadContext
, but I've never seen a complete example, other than a no-op
implementation that just uses the default context, but I think that might prevent loading multiple versions at the same time.
Another example of loading multiple versions of an assembly in the same process on the .NET Framework is using App Domains. But that's definitely .NET Framework only, in case you need to support .NET Core or the future One.NET (.NET 5). AssemblyLoadContext
is the closest thing to app domains in .NET Core, but isn't the same thing.
To the best of my knowledge, Mono doesn't support loading multiple versions of an assembly at the same time, but my guess is that this will change once .NET 5 is released. But it's a guess that lacks any evidence or inside knowledge whatsoever.