Over the next few days I'm going to try and blog a bit more on technical stuff. It's going to be in the format of short and simple tips and tricks for improving productivity and the pleasures of development.
Tip for today is the use of conditional compilation.
Basically VS.NET allows you to set 'Conditional Compilation Constants' in the build properties of each solution configuration. You can then use these constants to enable and disable the compilation of certain areas of code based on the configuration you are working it. Out of the box the debug configuration has a flag called DEBUG. This means that we can write code like this that allows us to distribute DEBUG builds to customers for testing without having to worry about whether they will distribute it more broadly:
#if
Another place where we have used conditional compilation is in libraries that have to target both the Compact Framework and the Desktop framework. Basically we can have a single set of source code files and use conditional compilation to deal with features that are present on one platform and not another- for example we use it to flag on and off compilation of code that places scrollbars on forms- a feature that is out of the box on the desktop framework but roll your own on the compact framework.