简体   繁体   中英

C# How to use two different versions of the same namespace (i.e. Kinect 1.8 and Kinect 2.0)

In C#, I want to reference Microsoft.Kinect (v1.8) and Microsoft.Kinect (v2.0) in the same project. They are different DLLs but use the same namespace. I am able to reference them both with a renaming hack in the .csproj file (by calling them "Microsoft.Kinectv1" a "Microsoft.Kinectv2" respectively.

The problem still remains of how to specifically reference one or the other in code though, since they both have the same namespace. Visual Studio notices that the some class is used in both asseblies (v1.8 and v2.0) but I don't know how to specify one version or the other in code. I have read several posts about this but none of these posts went as far as showing specifically how to solve this issue. How would this be done?

  1. In the properties window give each assembly a different alias (lets say you named them: assem01 and assem02);

  2. At the TOP of the file you want to use the same namespaces write:

    extern alias assem01;

    extern alias assem02;

Note: These lines MUST be written before any other code in the file.

  1. Now you can access the same namespace from both assemblies, for example:

    var c1 = new assem01::ns1.ns2.myClass();

    var c2 = new assem02::ns1.ns2.myClass();

  2. For convenience, you may wish to give some aliases to the namespaces too, for example:

    using assem01_ns2 = assem01::ns1.ns2;

    using assem02_ns2 = assem01::ns1.ns2;

    var c1 = new assem01_ns2.myClass();

    var c2 = new assem02_ns2.myClass();

Hope this was helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM