Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio loading the right (x86 or x64) dll

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?

like image 555
damnpoet Avatar asked May 04 '10 01:05

damnpoet


People also ask

What does x64 mean in Visual Studio?

Meaning, it will run as 64-bit on a 64-bit machine and 32-bit on a 32-bit machine. If the assembly is called from a 64-bit application, it will perform as a 64-bit assembly and so on.

What is the difference between Visual C++ x64 and x86?

The x86 libraries are for 32-bit applications, and the x64 libraries are for 64-bit applications. You can see which platform you are targetting in Visual Studio's Configuration Manager.

How can I tell if my net assembly is 64-bit?

You might also want to check out this one: check-if-unmanaged-dll-is-32-bit-or-64-bit. In later version of CorFlags, corresponding to . NET 4.5, "32BIT" was replaced by "32BITREQ" and "32BITPREF"..


2 Answers

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>
like image 70
Preet Sangha Avatar answered Oct 25 '22 01:10

Preet Sangha


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>
like image 38
Ron Avatar answered Oct 25 '22 01:10

Ron