4

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

Oleg Vazhnev
  • 23,239
  • 54
  • 171
  • 305
  • For deployment you can either write the manifest or manually load the x86/x64 DLL using the Assembly class. Detecting x86/x64 in run-time is a simple sizeof(IntPtr) == 4 or 8. There similar questions on SO. The thing you do with .csproj is OK, I think. – Viktor Latypov May 30 '12 at 08:44
  • do you actually require to have separate versions of your assembly? Can't you simply set the target to anycpu ? – Steve B May 30 '12 at 15:56
  • @Steve B, yes I do, otherwise certain dlls will not be loaded – Oleg Vazhnev May 30 '12 at 16:03
  • yes, I agree with Viktor, your changes to the .csproj file is fine. – C.J. May 30 '12 at 16:10
  • @CJohnson but they would be too complicated.... in my example I use only x86/x64, but I also need to use Debug/Release, so that would be 4 items totally... – Oleg Vazhnev May 30 '12 at 18:36
  • You should not reference Debug builds...... – Security Hound May 30 '12 at 20:22
  • @Ramhound what if I want to debug my application including referenced class libraries? – Oleg Vazhnev May 31 '12 at 08:17
  • 2
    As you're obviously building the referenced assemblies, why not just put them all in the same solution? Use project references instead of path references. You could then select the correct configuration for whatever target combination you want. – Brannon Aug 04 '12 at 05:19
  • @Brannon you are probably right, I just have to use "project references" – Oleg Vazhnev Aug 04 '12 at 10:30

2 Answers2

1

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.

Erdogan Kurtur
  • 3,630
  • 21
  • 39
0

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

Rohan D
  • 464
  • 6
  • 17