22

我正在使用 x86 中的 Visual Studio。我想为 x32 和 x64 构建我的应用程序。但我需要使用 sqlite .net 连接器,它有一个用于 x86 应用程序的 dll 和另一个用于 x64 应用程序的 dll。

如何配置我的 Visual Studio 以在我的配置为 x64 时加载引用,而在我的配置为 x86 时加载另一个引用?

4

3 回答 3

22

在您的项目文件中参考使用 MSBUILD 条件

<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>
于 2010-05-04T01:18:25.577 回答
10

这个比 Preet Sangha 稍微简单的答案在加载项目时不会生成警告,并且只有有条件接受的 dll 才会出现在解决方案资源管理器中。所以,总的来说,外观更干净,虽然更微妙。(这是在 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>
于 2011-10-05T23:45:33.513 回答
0

您还可以为“任何 CPU”构建应用程序并动态选择要加载的 DLL。

于 2011-01-19T05:22:25.070 回答