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.
 
    