0

Suppose we have two different versions of ClassLibrary.dll in which are not compatible. I mean there might be some classes and methods in version 1 that are deprecated in version 2 and also some new features in version 2. Is there any way to detect version of the imported assembly at compile time? For example something like this:

<DefineConstants Condition=" ClassLibrary.Version == '2' ">RUNNING_ON_V2</DefineConstants>

Therefore I can use the RUNNING_ON_V2 in my code as follows:

#if (RUNNING_ON_V2)  
        Console.WriteLine("Using v2");
        ClassLibrary.NewMethod();  
#else
        Console.WriteLine("Using v1");
        ClassLibrary.DeprecatedMethod();
#endif  

Update

According to this question we could detect version of the assembly at run-time but I need to detect version of the imported assembly at compile time.

It seems to me that it is possible by MSBUILD or App.config.

Community
  • 1
  • 1
a.toraby
  • 3,232
  • 5
  • 41
  • 73
  • Possible duplicate of [Programatically get the version number of a DLL](http://stackoverflow.com/questions/1755504/programatically-get-the-version-number-of-a-dll) – Fruchtzwerg Jan 08 '17 at 20:05
  • @Fruchtzwerg The question you proposed as a duplicate is totally different. I'm talking about detecting the version of the imported `dll` at `compile time` not `run-time`. – a.toraby Jan 08 '17 at 20:22
  • Where is the point in doing that? When you change the reference at compile time, why would you need to keep legacy code? And if for some reason you would want to manually switch back and forth, why don't you introduce a conditional compile definition that you can also manually turn on and off? – Sefe Jan 08 '17 at 21:01

0 Answers0