I have a C# .NET Compact Framework 3.5 mobile project in Visual Studio 2008. The program uses a barcode scanner and works for two different types of Windows Mobile devices (both using their own SDK to manipulate the barcode scanner). How can I conditionally add the reference to the scanner SDK SDK DLL file? i.e., if compiling for HARDWARE1 configuration I don't want to add a reference to HARDWARE2-SCANNER-SDK.DLL.
You can specify which DLL(s) to load in your app.config file and then use the Assembly.Load method to load the proper library(libraries.)
That's the simple answer. But to really make this work you might need to create a few "wrapper" assemblies that share a common API (also in a separate library) so that your final application will not have to care where your scanner info is coming from. It should be ignorant of what hardware is being used.
Btw: This is all related to the concept of dependency injection, albeit at the module rather than a class level. Here are a couple of resources to get you started:
http://msdn.microsoft.com/en-us/magazine/cc163739.aspx http://en.wikipedia.org/wiki/Dependency_injection
Why do you need to? If you use an interface for the scanner access, then one implementation will reference one SDK and the other implementation will reference the other SDK.
At run time the class you actually create will attempt to load the referenced assembly and if you're detecting the hardware before instantiating then the proper SDK reference will get loaded. Basically if you don't use the SDK that isn't present, then it will never try to load it.
The only reason this would be a problem is if the two SDKs use the same class names. In that case I'd still interface base it, but have a different DLL for each implementation of the interface and those projects would reference their proper SDK.