开发者

How do I build a project in Any CPU mode when dealing with 3rd party libraries?

开发者 https://www.devze.com 2023-02-07 23:54 出处:网络
I have a third party library that is available for download in either 32-bit or 64-bit .dlls. My development machine is running 32-bit Windows 7. My target production machine is running 64-bit Windows

I have a third party library that is available for download in either 32-bit or 64-bit .dlls. My development machine is running 32-bit Windows 7. My target production machine is running 64-bit Windows Server 2008 R2. My project solution is currently build开发者_开发问答ing in Any CPU mode.

Is there an elegant way to handle this case without having to have duplicate projects (MyProject32 and MyProject64, each referencing the appropriate 32 or 64-bit version of the 3rd party library)?

The first solution I thought of is to hook into the AppDomain.AssemblyResolve event, and have my 3rd party libraries in their own 32 and 64-bit sub-folders. I'd then load the appropriate assembly dynamically based on the current mode.

The second solution I thought of is to build in 32-bit mode only, and only use the 32-bit 3rd party library (which seems like a cop-out to me...).

Neither solution makes me feel particularly clean... Any advice would be helpful!


If this is an in-house program, then I don't see the problem. Install the 32-bit DLL on the development machine and install the 64-bit DLL on the production machine. Don't install the wrong DLL on the wrong machine. With an in-house app, the problem of the wrong DLL on the machine is pretty much equivalent to not having the DLL there at all.

If this is an application that you'll be distributing, or you can't depend on the machines having the right DLLs in the right place, then your first solution sounds reasonable: figure out which DLL is appropriate for the current runtime environment, and load it. Or, if it can't be loaded, display an error message indicating what the problem is.

0

精彩评论

暂无评论...
验证码 换一张
取 消