2010-05-04 97 views
22

我正在使用x86中的visual studio。我想爲x32和x64構建我的應用程序。但我需要使用sqlite .net連接器,它有一個用於x86應用程序的dll和另一個用於x64應用程序的dll。如何配置我的Visual Studio加載引用時,我的配置是x64和另一個時,我的配置是x86?Visual Studio加載正確的(x86或x64)dll!

謝謝, Richard。

回答

21

在參考使用一個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> 
+0

謝謝你的工作! ;) – damnpoet 2010-05-04 01:59:01

0

您也可以建立自己的應用程序爲「任何CPU」,並動態選擇加載哪個DLL項目文件。

+0

你有一個例子嗎? – 2012-02-01 03:00:00

+0

您需要查看掛鉤事件AppDomain.CurrentDomain.AssemblyResolve。然後,您可以使用Assembly.LoadFrom從任何位置加載它來解析任何DLL(例如System.Data.SQLite.dll)。您甚至可以將這兩個版本的DLL作爲嵌入式資源發佈。 – antsyawn 2012-02-07 05:37:57

10

這個比Preet Sangha更簡單的答案在項目加載時不會產生警告,並且只有條件接受的dll纔會出現在Solution Explorer中。因此,總體而言,外觀更清潔,但更爲微妙。 (這在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> 
+1

不錯的。非常好的答案+1 – 2012-02-01 02:59:36

相關問題