开发者

Add Reference dynamically to my project

开发者 https://www.devze.com 2023-04-02 05:16 出处:网络
I am Developping an Add-In for Microsoft Word. In my Add-In 开发者_运维问答i am using a reference to file \"Microsoft.Office.Interop.Word.dll\" so i can use word objects.

I am Developping an Add-In for Microsoft Word. In my Add-In 开发者_运维问答i am using a reference to file "Microsoft.Office.Interop.Word.dll" so i can use word objects.

In case the development machine has word 2007 installed, the file to be included in references is version 12 in case word 2010 is installed, the file should be version 14.

how can i build my add in and make it work regardless of which version of Word is installed on the machine (in other word tell my application to automatically detect which version of office is installed and use the appropriate interop file automatically)?


If your actual code is making reference to the items in the given assembly, trying to hook into a different version could actually cause errors (e.g. if certain method signatures have been changed). In most cases, the best strategy would be to produce different builds to target the different DLL versions, and install the correct build on the user's machine.

There are strategies you can use to make this easier, like wrapping your calls to this library in a set of interfaces, and then having two main "plugin" assemblies that provide implementations for the interfaces, but which target different DLLs when they implement them. The software can load the implementation bindings dynamically by configuration, similar to the way popular Dependency Injection frameworks do. That way, if a method signature changes from one version to the other, you can just change a single class and the rest of your code will still work as-is.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号