简体   繁体   中英

how to add reference to class library if I need both 32 bit and 64 bit

In my project I'm using both configurations - 32 bit and 64 bit (because i'm developing on 32bit machine but deploy to 64 bit machine).

My project contains class library, that located at "C:...\\Commons\\bin\\Debug\\Commons.dll". I've added this dll to References, but of course when I've switched to 64-bit this doesn't work.

So I need mechanism of adding "platform-specific references".

I know that I can hand-edit .csproj file to add something like that:

<Reference Include="Commons" Condition="$(Platform) == 'x64'">
  <HintPath>..\Commons\bin\x64\Release\Commons.dll</HintPath>
</Reference>
<Reference Include="Commons" Condition="$(Platform) == 'x86'">
  <HintPath>..\Commons\bin\x86\Release\Commons.dll</HintPath>
</Reference>

Should I do the same for Class Library?

I just wonder that VS doesn't support mechanism of "platform-dependent references" even for Class Libraries?

upd it seems i actually need to link 4 types of dll somehow - x86/Debug, x86/Release, x64/Debug, x64/Release

In fact you shouldn't. You must compile your code to MSIL, and add references to MSIL versions of dlls. Your code and referenced code will be compiled by runtime on runtime. If it works on a x86 computer then it will be compiled to x86 and on a x64 computer it will be compiled to x64. You do not need to worry about it.

If you think JIT is slow and you need performance, yoou can NGen your assemblies on target computers.

Following question has solution to your problem. Hope this helps.
Conditionally use 32/64 bit reference when building in Visual Studio

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM