Visual Studio loading the right (x86 or x64) dll!

陌路散爱 提交于 2019-11-28 19:22:18

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>

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>

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!