Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Developing on both 32 bit and 64 bit processors, how should I structure my project to automatically reference the right dlls?

I am currently in a situation where I have both 32 bit and 64 bit developer machines working on my c# project. I have to reference a couple dlls that have both a 32 bit and a 64 bit version. Obviously, the 32 bit machines need to reference the 32 bit dll, and the 64 bit machines the 64 bit dll. The issue I am having is that every time a developer checks in some code, they also check in their dll references, so when someone on the other side pulls their code, it doesn't build, and they have to manually update their references back to what they should be. Then they check in, and the other developers have to manually fix their references, etc. etc. ad nauseum.

I don't imagine this is a new problem, but it is the first time I have run into it. Is there a common practice to have a project automatically reference the correct dll for the CPU? Or perhaps a way to have a 32 bit and 64 bit project, each with the correct references, and a way (possibly a command line tool or some outside that can be tied into a build) to tie them together so that when new items are added or removed to one, the other will also be updated?

The other option is to have every developer use the same virtualized development environment. If I go this route, can I virtualize a 64 bit system on 32 bit hardware, or do I have to go the other way, and virtualize 32 bit. This will be a SaaS product, so I only have to deploy for one processor, and I would prefer that to be 64 bit.

like image 269
Matthew Vines Avatar asked Dec 26 '10 20:12

Matthew Vines


People also ask

How can I run a 64-bit DLL on a 32-bit application?

You cannot call a 64-bit DLL from 32-bit LabVIEW. This is a limitation of 64-bit Windows, which does not support mixed 64-bit/32-bit processes. The recommended solution is to recompile the DLL from the source code for a 32-bit target architecture.

Can we use 32-bit DLL in 64-bit application C#?

A 64bit executable cannot call a 32bit dll and viceversa. Unless you actually need your application to be 64bit, the simplest option is to set it to target x86. This will still allow it to run on both 32 and 64bit versions of Windows.

How do I change my Visual Studio application from 32-bit to 64-bit?

Choose the Configuration Manager button to open the Configuration Manager dialog box. In the Active Solution Platform drop-down list, select the <New...> option to open the New Solution Platform dialog box. In the Type or select the new platform drop-down list, select a 64-bit target platform.


2 Answers

Here you find an example for how to change the assembly reference according to your target platform:

http://www.ryangerard.net/post/8768828095/how-to-change-visual-studio-assembly-references

(You have to change the .csproj files manually). And not to forget, on the 32 bit machines choose 'x86' as target platform, while on the 64 bit machines, choose 'x64').

like image 167
Doc Brown Avatar answered Sep 30 '22 15:09

Doc Brown


I have a similar issue but my solution is a bit different. I simply have all the developers develop with the x86 DLLs.

So, the code is actually identical on all machines. Then, at run time (and for testing), I use a launcher app which will test the OS and move around the DLLs so that at runtime the proper DLLs are used. The logic in the launcher is quite simple. Something like:

If IntPtr.Size = 8 Then
  '-- Copy x64 DLLs into position
Else
  '-- Copy x86 DLLs into position
End If

Of course, when copying, you need to copy back so you can always switch between x64 and x86 (in the case of a portable application). However, if you're installing a non-portable application then there is no need for the launcher as this OS check can all be done inside the installer (so only the proper DLLs get installed).

You will need to edit your project file to use a non-specific version of the DLLs in question (otherwise this moving around logic will not do what you want it to).

like image 39
John Avatar answered Sep 30 '22 16:09

John