Reputation: 1362
I have several configurations with my app to make debug/release builds and also 32 bit and 64 bit builds. Now with 32 and 64 bit builds I would need to reference different dlls (namely those build with x86 and those build with x64) but the references seem to be global for my project and don't depend on the configuration. Now I always have to exchange the references when I switch from 32 bit to 64 bit build (and vice versa). What is the appropriate way to achieve different references for different configurations?
Upvotes: 4
Views: 613
Reputation: 49965
This can be done with a little bit of manual manipulation of the project files.
First you need to right click on the project, and click Unload Project. Then right click on it again and select Edit [project name].
When it is loaded in the editor you will see various entries for your refences:
<ItemGroup>
<Reference Include="System.Xml" />
<Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationCore">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Common\Lib\3rdParty\Prism\4.0\Desktop\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference>
</ItemGroup>
Note that these are inside an ItemGroup
node.
You can now perform a little magic... add an expression to your ItemGroup so that it is only used if the build configuration is a certain bitness:
<ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<!-- these are the references used when there is a Release x86 build -->
<Reference Include="System.Xml" />
</ItemGroup>
Note that there is no way to do this through the UI, so you will have to manually manage these reference lists (e.g. if you need to add another reference).
Also note that this is not a hack... it is simply utilising one of the features of MSBuild (which is used by VS to build your projects). You can have as many of these ItemGroup
lists as you like using any expression you like - if it doesn't have an expression then it will always be included in the build.
Upvotes: 2
Reputation: 865
Consider using runtime assembly binding
http://msdn.microsoft.com/en-us/library/twy1dw1e.aspx
This will replace your assemblies with ones defined in binding based on setup.
Upvotes: 0
Reputation: 1655
You can make any section of your csproj conditional on the configuration and/or platform, so you can put your references inside a separate section(s). Note that I think this will force rebuilds each time even if there are no changes since VS can no longer be sure if a rebuild is required. May not be an issue but it will add to the compile time.
e.g.
<ItemGroup Condition=" '$(Platform)' == 'x86' " >
<Reference ...86bit DLL... >
</ItemGroup>
<ItemGroup Condition=" '$(Platform)' == 'x64' " >
<Reference ...64bit DLL... >
</ItemGroup>
I think you can alternatively make the hint path of a reference conditional if nothing in the signature changes between them but I can't remember.
Upvotes: 1