Conditional Reference

a 夏天 提交于 2019-12-20 01:37:45

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7798052/conditional-reference

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!