简体   繁体   中英

Load any version of a statically referenced .NET assembly

I'm working on an tool that uses .NET assemblies from another product. A handful of the assemblies are statically referenced in my project (using "Add Reference") because I need to actually use those types in my code. But I load many other assemblies dynamically from the install directory of the product, using reflection to dynamically instantiate whatever objects I need.

I don't want to have to recompile and publish a separate version of my project for every possible version of the product I depend on. Some version of the assemblies I need will definitely be present in the application install directory, so I'd like to use whatever version of the assembly happens to be installed. But it will probably not be exactly the same version as the assembly that I originally used when building my tool. (The product versioning strategy is such that all the assemblies in the product have the same version number, which changes every release, even if the particular assemblies I need static references to haven't changed since the previous release, or support 100% of the APIs I require).

Is it possible to achieve this?

Assembly Version redirects allow me to load a particular version of an assembly when a different version of that assembly is requested. My situation is the inverse of that; I want to load whatever version happens to be present.

您可以绑定到AppDomain.CurrentDomain.AssmeblyResolve事件并自行处理解决方案。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM