Thijser
Thijser

Reputation: 2633

How to add reference to two versions of the same api in visual studio/c#

I have a project that depends on an external program, this external program has an API, well actually it has about 17 different APIs all slightly different for version 2000-2017. Now within these 17 versions I want to support about 5 of them. (2012-2017) but there are several features that were in 2012 that have since been renamed in 2017.

Now the good news is that I can trivially determine which version of the program a given user is using and any shared functions (90%+) can be called using a reference to a different version of the API. However I need some of the remaining 10% of the features. So I need to include the references to multiple APIs so that my program will compile and then at runtime pick which version it receives.

Now what I tried is to go into the visual studio (2015 community version), and add a reference to several of thes. However the moment I try adding in a second reference I get a error message: a reference to [API.dll] could not be added a reference to the component [API.dll] already exists in project..

I would like the method use to be such that if a function with a given name exists in one of the versions it should bind to that one and if a given function name exists in multiple APIs then it should bind to the latest. Any idea how to do this? Maybe something using the extern alias keyword? I looked at How to reference two versions of an API? and the accepted answer won' t work but the second answer might, anyone capable of explaining if that one will work and if so how to do it correctly?

Upvotes: 1

Views: 582

Answers (1)

umeshkumar sohaliya
umeshkumar sohaliya

Reputation: 267

Basically, it is not allowed to add multiple references with the same name.

If you are the assembly owner, you have to change the file name in the manifest to generate DLLs with different names.

You can also manage the assembly version in the configuration file or load at runtime.

My suggestion is to merge all the DLLs into a single file. You can use ILMerge to do this.

Upvotes: 2

Related Questions