19

I'd like to make a x86 and x64 version of my application because some of the libraries I'm using have differences for x86 and x64 (e.g. SQLite). I made a new configuration for release builds that has as target operating system "x64".

Is there a way to define different DLLs for the configuration e.g. use SQLite.dll for x86 release and SQLite64.dll for x64 release?

  1. Unfortunately I can't use the "any platform" option which is default because of those not x64 compatible DLLs.
  2. I want to support real x64 and not running a 32 bit application on an x64 OS.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kai
  • 5,850
  • 13
  • 43
  • 63
  • This is a good question, I have a similar issue with one 3rd party .dll that we use that has specific 32 and 64 bit version so whilst its not a problem for most of my code as that's managed and targets the CLR - getting the right version of the .dll for specific targets is an issue I haven't resolved yet – Murph Jan 30 '10 at 21:46

4 Answers4

13

You can add conditions to the dll references in the project file but you cannot do it using Visual Studio - you will have to hand-edit the project files. See this for how to do it.

What you need to do is to include a reference to the 32-bit dll only in the 32-bit build configuration, and a reference to the 64-bit dll in the 64-bit build configuration.

Community
  • 1
  • 1
adrianbanks
  • 81,306
  • 22
  • 176
  • 206
  • The above is correct. You can manually edit the project file and add the Condition attributes. – sourcenouveau Jan 30 '10 at 22:09
  • Wow, didn't even know that I was looking for an answer to this question, but that rocks. Would I be correct in thinking that in this circumstance, the condition should be on $(Platform), since that is independent of debug/release? – Peter T. LaComb Jr. Jan 30 '10 at 22:24
  • @Peter: Yes, you need to add something like `Condition="$(Platform) == 'x64'"` to the relevant node in the project file. – adrianbanks Jan 30 '10 at 22:46
  • something like Condition="$(Platform) == 'x64'"? is that the correct syntax? – Kai Jan 30 '10 at 23:19
  • shall I better do set the conditon by build configuration? – Kai Jan 30 '10 at 23:22
  • 1
    @Kai: That syntax looks correct. You need to set it based on what it is that needs to be different. If the reference is the thing that differs between x86 and x64, add both dlls as references, then edit the project file and put `Condition="$(Platform) == 'x86'"` in the reference node of the x86 dll and `Condition="$(Platform) == 'x64'"` in the reference node of the x64 dll. – adrianbanks Jan 31 '10 at 00:17
1

You need a condition to the dll reference in the project file.
This will cause visual studio to recheck the condition and reference whenever you change the active configuration.
Just add a condition for each configuration.

Example:

 <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <Reference Include="DLLName">
      <HintPath>..\DLLName.dll</HintPath>
    </Reference>
    <ProjectReference Include="..\MyOtherProject.vcxproj">
      <Project>{AAAAAA-000000-BBBB-CCCC-TTTTTTTTTT}</Project>
      <Name>MyOtherProject</Name>
    </ProjectReference>
  </ItemGroup>
Yochai Timmer
  • 48,127
  • 24
  • 147
  • 185
0

Which VS version? Which language are you developing in? If native (=not managed) C++, practically all settings, including used libraries can be set differently for each configuration. In the top of the project properties dialog, just choose which configuration's settings would you like to modify.

shojtsy
  • 1,710
  • 3
  • 17
  • 24
0

It exists the build-in keyword Choose and When for csproj file.

Example below:

<Choose>
  <When Condition="'$(Configuration)' == 'DebugConversion'">
    <ItemGroup>
        <ProjectReference Include="..\OfficeConverer\WordConverter\OfficeConverter.csproj">
            <Project>{b0cbxxxx-xxxx-xxxx-xxxx-7f3353aaxxxx}</Project>
            <Name>Saur.OfficeConverter</Name>
        </ProjectReference>
    </ItemGroup>
  </When>
  <Otherwise>
    <ItemGroup>
        <Reference Include="OfficeConverter, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
            <HintPath>..\packages\OfficeConverter.1.0.1\lib\net45\OfficeConverter.dll</HintPath>
        </Reference>
    </ItemGroup>
  </Otherwise>
</Choose>

Bref explication: when choosing "DebugConversion" in Visual Studio, the project will load a project name OfficeConverter in the solution, otherwise (such as "Debug" / "Release" by default) a Nuget Dll would be restored and loaded.

Yang C
  • 536
  • 5
  • 16