22

I'm working on Visual Studio in an x86. I would like to build my application for both x32 and x64. But I need to use the sqlite .net connector which has a dll for x86 apps and another dll for x64 apps.

How do I configure my Visual Studio to load a reference when my configuration is x64 and another when my configuration is x86?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
damnpoet
  • 223
  • 2
  • 5

3 Answers3

22

in your project file in reference use an MSBUILD conditional

<Reference 
       Include="SomeAssembly86, Version=0.85.5.452, Culture=neutral, PublicKeyToken=41b332442f1101cc, processorArchitecture=MSIL"  
         Condition=" '$(Platform)' == 'AnyCPU' ">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\Dependencies\SomeAssembly.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference 
         Include="SomeOtherAssembly, Version=0.85.5.999, Culture=neutral, PublicKeyToken=41b332442f1101cc, processorArchitecture=MSIL" 
         Condition=" '$(Platform)' == 'x64' ">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\Dependencies\SomeOtherAssembly.dll</HintPath>
      <Private>False</Private>
    </Reference>
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
10

This slightly simpler answer than Preet Sangha's will not generate a warning when the project is loaded and only the conditionally accepted dll will appear in the Solution Explorer. So, overall, the appearance is cleaner, although more subtle. (This was tested in Visual Studio 2010.)

<Reference Include="p4dn" Condition="$(Platform) == 'x86'">
  <HintPath>..\..\ThirdParty\P4.Net\clr4\x86\p4dn.dll</HintPath>
</Reference>
<Reference Include="p4dn" Condition="$(Platform) == 'x64'">
  <HintPath>..\..\ThirdParty\P4.Net\clr4\x64\p4dn.dll</HintPath>
</Reference>
Ron
  • 1,888
  • 20
  • 25
0

You can also build your application for "Any CPU" and dynamically choose which DLL to load.

antsyawn
  • 971
  • 10
  • 17
  • You need to look at hooking the event AppDomain.CurrentDomain.AssemblyResolve. You can then resolve any DLL (e.g. System.Data.SQLite.dll) by loading it from any location using Assembly.LoadFrom. You can even ship both versions of the DLL as embedded resources. – antsyawn Feb 07 '12 at 05:37