Developing for multiple architectures

When writing code for the BoxLab (or other applications) you may frequently want to use it on both Mobile and PC architectures. Due to the way Visual Studio and C# work, you need to create a different project for each architecture, and then do some magic to share the code between them:


We want to keep all of our code files in a special Code folder and then maintain separate (mostly empty) project folders for each architecture:

<Visual Studio projects folder>
  • MyProject
    • MyProject.sln
    • Code
    • MyProjectMobile
      • MyProjectMobile.csproj
    • MyProjectDesktop
      • MyProjectDesktop.csproj

Setting this up in Visual Studio

  1. First, decide what you want to call the project. For example, MyProject.
  2. First, go to File > New > Project. Pick one of the architectures you want to be using; in this example we'll create a Windows CE 5.0 project.
  3. We want the solution space to be named MyProject, but the actual project itself to be named MyProjectMobile. How?
  4. Set the project name to MyProjectMobile
  5. Set the solution name to simply MyProject

Now create additional projects (File > Add > New Project) for each remaining architecture (for example, MyProjectPC).

Finally, navigate to the solution folder and create a new folder called Code. The whole thing should now look like the layout described in the previous section.

Writing code

  1. Create code files by going to File > New > File..
  2. Save them in the Code folder.
  3. For every architecture project,
    1. Right-click on the project > Add > Existing Item
    2. Locate your code file
    3. Click the arrow next to the Add button and select Add as link

Important Notes

  • I strongly suggest trying to keep the code in these types of libraries as platform-independent as possible. If you must make distinctions:
    • Right-click on a project > Properties
    • Build tab
    • Under Conditional compilation symbols add a symbol that reflects the architecture (PC, Mobile, PowerPC, etc.)
    • When writing code, you can now differentiate using compiler directives:

#if( Mobile || PowerPC)
Mobile-specific code

Desktop-specific code

NOTE: This is super-kludgy. But sometimes necessary.