【发布时间】:2013-05-21 22:00:09
【问题描述】:
我有一个配置为“任何 CPU”的项目。 现在我必须分别引用具有 x86 和 x64 编译版本的第三方 dll(我无法获得第三方 dll 的 AnyCPU 版本)。 我已将项目的配置文件更改为基于平台引用特定的 dll,如下所示。(这是一个示例项目配置文件)
<PropertyGroup>
<CurrentPlatform>x86</CurrentPlatform>
<CurrentPlatform Condition="'$(PROCESSOR_ARCHITECTURE)'=='AMD64' or '$(PROCESSOR_ARCHITEW6432)'=='AMD64'">x64</CurrentPlatform>
</PropertyGroup>
<ItemGroup Condition=" '$(Platform)' == 'x86' ">
<!--Compiled as ClassLibrary target platform is x86-->
<Reference Include="ClassLibrary">
<HintPath>..\..\ClassLibrary_x86\ClassLibrary_x86\bin\Debug\ClassLibrary.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(Platform)' == 'x64' ">
<!--Compiled as ClassLibrary target platform is x64-->
<Reference Include="ClassLibrary">
<HintPath>..\..\ClassLibrary_x64\ClassLibrary_x64\bin\Debug\ClassLibrary.dll</HintPath>
</Reference>
</ItemGroup>
当我在 Visual Studio 中运行此项目时,它无法正常工作。抛出 BadImageException。当我将我的项目目标平台更改为 x86 并运行应用程序时,它将工作。如果我将其更改为 x64,则抛出相同的 BadImageException。
这里有什么问题吗?我不想仅仅因为一个 dll 引用而创建两个项目(x86 和 x64)。如果上述方式错误,还有其他方法可以继续吗?
我的开发环境是VS2010和.NET4.0和Win7 64bit OS。
【问题讨论】:
标签: c# x86 64-bit 32bit-64bit dll-reference