Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional Reference

I have an application that I was writing that communicates with a third-party application via a Component Object Model library. I must reference this COM library within the Visual Studio project itself in order for the application I am writing to work. There is also a .NET wrapper library that I must reference in the Visual Studio project in order to communicate with the COM library.

Is there a way to to create a conditional initialization of a class, in order to use a method within a .NET class within the .NET wrapper library, that will work in a later version of the third-party COM library itself.

The problem I ran into was that I was trying to reference a feature of the COM library that only existed in a later version. The version of the wrapper itself was identical because it was backwards compatible. When I attempted to access this new feature the program I was writing would silently close when I started it when the previous version of the third-party application was installed.

Is there a way I could have avoided this behavior without changing how the way the application itself was built?

like image 764
Security Hound Avatar asked Dec 09 '22 05:12

Security Hound


1 Answers

Not sure whether I understand term "reference a class".

You can do a conditional referencing of an entire Assembly (DLL)

<Reference 
        Include="LegacyServices.dll" 
        Condition="$(AppVersion == '2.0')" />

or conditionally include a source file into a project

<Compile 
       Include="LegacyServices.cs" 
       Condition="$(AppVersion == '2.0')" />

Both using MSBuild Condition in csproj file.

like image 199
sll Avatar answered Jan 20 '23 01:01

sll