Visual Studio 2010 - Setting different set of reference libraries for different target platforms
If you are playing with x86 and x64 with Visual Studio 2010, you may soon realize that it does not provide a way for developers to add specific reference libraries for specific target platform.
If you add at VS2010 IDE, you will end up adding all x86 and x64 references to the single Reference tree. Even if you switch to your desire target platform before adding the reference, it will not work.
VS2010 treats all references are required for every target platforms, however, x86 and x64 requires different set of dll for respective build.
Here is a step by step guild for provide different set of reference library for different target platform.
1. Put your library/reference (mainly dll) to your/path/to/lib/x86 or your/path/to//lib/x64 for x86 and x64 library/reference respectively
2. Open your_master.sln
3. At solution explorer, look for your_proj-> reference
4. For consistency, make sure you had switch your project target platform to Debug | x86
5. Add your desired reference. We added C1.Common.dll in this example. After adding, you should see the following
6. Close your solution and save it if required
7. Open your_proj.csproj in a XML or Text editor. You may want to create a backup (ie, your_proj.csproj.bak) before opening it for modification
8. You will see something like the following
9. Make sure you have the following in the your_proj.csproj xml file. They are your platform target in the your_proj.csproj. If they does not exist, please create them at Visual Studio 2010 (See how to create addition target platform)
10. Next, make sure each of the above Property Group have the following tag. They are the Reference Path for each target platform. Please add if it does not exist
11. Next, make sure you have the followings elements. They are the place holder for your reference libraries for each target platform
12. Now, you are ready to add a new reference library
13. Look for the following in the xml. This is the default ItemGroup for all target platform
14. As you can see, C1.Common is within a Reference tag. This is the reference library you have added. Now, copy the whole Reference tag and paste to all ItemGroup stated in point 11. Below is an example
15. Note the following when you perform point 14
a. The essential tag for Reference are
i. Include – This allow you to define a common name for the library. As you can see, I declare C1.Common for all target platforms.
ii. HintPath – The allow you to set absolute or relative path to the dll. As you can see, I use $(ReferencesPath) as a common variable to locate the dll. Setting ReferencesPath is shown in point 10.
16. Save the your_proj.csproj file
17. To verify your setting. Open the your_master.sln, at Solution Explorer -> Reference and double click on the newly added library. The object browser will open up
18. By switching to different target platform, the object browser will update respectively.
19. Note the following
a. If you want to remove a library, remove it at the xml. If you remove the library at Visual Studio Solution Explorer, it will change the xml and remove your Debug|x86 ItemGroup
b. Give a common Include name at point 14 will cause the Reference at Solution Explorer to display a single reference. Otherwise, it will display all references (one for each target platform). Also, depend on your reference path for the selected target platform, it may show some of them as missing reference.
c. If you are familiarized with the csproj xml, you should add the reference directly at the xml.