简体   繁体   中英

Can I use the C# preprocessor to skip Kinect v2.0 code?

Quick question, I'm developing a small program which I'd like to work with Kinect versions 1 and 2. Is there a preprocessor command I can use so that the c# compiler skips my Kinect v2.0 code if I don't have the Kinect 2.0 sdk installed? (When I'm working on Windows 7 for example).

Basically, like this:

#if KINECT1
   // ... kinect1 specifict code
#endif

#if KINECT2
   // ... kinect2 specific code
#endif

Of course, you would have to define those symbols manually , there is no builtin capability in the compiler or framework to detect which version is available, if at all.

You might be able to detect any installed Kinect SDK (version) by using MSBuild. Like for example, look for specific registry keys, paths on your local drives and/or set environment variables and then set those symbols from inside your project files.

For example, include the following fragment on the top of your .csproj file (or put it into a separate file that you <Import> ).

 <PropertyGroup Condition="Exists('C:\Program Files\...\Whatever\v1.0')">
     <DefineConstants>KINECT1;$(DefineConstants)</DefineConstants>
 </PropertyGroup>
 <PropertyGroup Condition="Exists('C:\Program Files\...\Whatever\v2.0')">
     <DefineConstants>KINECT2;$(DefineConstants)</DefineConstants>
 </PropertyGroup>

(Mind you, the above if just an example though, no idea what would be good "trigger" to detect the version for kinect).

UPDATE

@Scott Chamberlain comment helped. Actually the Kinect 1.0 SDK sets the KINECTSDK10_DIR environment variable and the 2.0 SDK sets the KINECTSDK20_DIR envrionment variable.

So, you might do something like this ( this might help as well):

 <PropertyGroup Condition="'$(KINECTSDK10_DIR)' != '' and Exists('$(KINECTSDK10_DIR)')">
     <DefineConstants>KINECT1;$(DefineConstants)</DefineConstants>
 </PropertyGroup>
 <PropertyGroup Condition="'$(KINECTSDK20_DIR)' != '' and Exists('$(KINECTSDK20_DIR)')">
     <DefineConstants>KINECT2;$(DefineConstants)</DefineConstants>
 </PropertyGroup>

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