如何构建引用相同项目的x64和x86项目 [英] How to build x64 and x86 projects that reference same projects

查看:99
本文介绍了如何构建引用相同项目的x64和x86项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个项目, ProjectA(exe) ProjectB(exe) ProjectD(类库)

项目A引用了System.Data.OracleClient.dll和ProjectD。项目B仅引用ProjectD。已安装oracle的32位客户端版本,因此ProjectA必须是32位应用程序。项目B可以构建为64位应用程序。

Project A references the System.Data.OracleClient.dll and ProjectD. Project B just references ProjectD. The 32-bit client version of oracle is installed and therefore ProjectA has to be a 32-bit application. Project B can be built as a 64-bit application.

项目A的构建设置:

平台:有效(x86)

平台目标:x86

项目B构建设置:

平台:活动(任何CPU)

Platform: Active (Any CPU)

平台目标:任何CPU

Platform target: Any CPU

我的问题是,ProjectD(类库)的构建设置应该是什么,当构建ProjectA和ProjectB时,其构建ProjectD会有所不同吗?就项目的通信而言,对CLR进行更深入的解释将是很好的。

My questions are what should the build settings be for ProjectD (the class library) and when ProjectA and ProjectB get built does it build ProjectD differently? A deeper explanation of the CLR would be great in terms of communications of the projects.

ProjectA和ProjectB将在64位Windows Server 2008上使用。无需安装,

ProjectA and ProjectB are to be used on 64-bit Windows Server 2008. No installation, just standalone exe's.

推荐答案

仅EXE项目的平台目标设置很重要。那是程序集,它首先被加载并确定整个过程的位数。

Only the Platform target setting for the EXE project matters. That's the assembly that gets loaded first and determines the bitness of the entire process.

一个DLL无法选择,它必须与EXE项目选择的内容兼容。因此,为DLL项目选择AnyCPU几乎总是正确的选择。

A DLL doesn't get a choice, it must be compatible with whatever was selected by the EXE project. Picking AnyCPU for a DLL project is therefore almost always the correct selection.

在少数情况下,您会使用显式设置。仅当您知道类库对某种本机代码具有依赖性(例如Oracle提供程序 ),并且尝试以错误的位运行该本机代码会产生完全的依赖关系时,才这样做。难以理解的异常。您可以通过选择DLL的Platform目标来避免该异常,并获得一个(略微)更好的异常,该程序将在尝试加载程序集时早期以BadImageFormatException失败。尽管该例外也不是非常有用的例外。管理员在决定真正的问题不在其他地方之前,将尝试几次重新安装DLL的可能性很小。

There are just a few cases where you'd use an explicit setting. You'd only do so if you know that the class library has a dependency on some kind of native code, like the Oracle provider, and that trying to run that native code in the wrong bitness produces a completely inscrutable exception. You can avoid that exception and get a (slightly) better one by picking the Platform target for the DLL, the program will fail with a BadImageFormatException early when it tries to load the assembly. Albeit that this exception isn't exactly a very informative one either. Some odds that an admin is going to try to reinstall the DLL a couple of times before deciding that the real problem is elsewhere.

因此,基本原则是:选择x86作为EXE项目,用于所有其他类库项目的AnyCPU,这对Oracle来说简直是天花乱坠的事情。

So basic ground rules: pick x86 for the EXE project, AnyCPU for all other class library projects, a nastygram to Oracle for doing nothing to make this easy.

这篇关于如何构建引用相同项目的x64和x86项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆