Referencing different versions of the same assembly

前端 未结 5 1430
忘了有多久
忘了有多久 2020-12-08 19:45

If A references assembly B 1.1 and C, and C references B 1.2, how do you avoid assembly conflicts?

I nievely assumed C\'s references would be encapsulated away and w

5条回答
  •  渐次进展
    2020-12-08 20:26

    A seemingly little known way of doing this is to use the extern keyword.

    From C# Reference

    To reference two assemblies with the same fully-qualified type names, an alias must be specified at a command prompt, as follows:

    /r:GridV1=grid.dll

    /r:GridV2=grid20.dll

    This creates the external aliases GridV1 and GridV2. To use these aliases from within a program, reference them by using the extern keyword. For example:

    extern alias GridV1;

    extern alias GridV2;

    Each extern alias declaration introduces an additional root-level namespace that parallels (but does not lie within) the global namespace. Thus types from each assembly can be referred to without ambiguity by using their fully qualified name, rooted in the appropriate namespace-alias.

    In the previous example, GridV1::Grid would be the grid control from grid.dll, and GridV2::Grid would be the grid control from grid20.dll.

提交回复
热议问题