在编译时基于Build Target加载不同的程序集

raj*_*jee 5 reflection c#-3.0

我想根据构建目标加载四个独立的C#程序集中的一个.这将进入带有.net framework 3.0的Web服务.

可能性:

32位调试:AmtApiWrapper32d.dll

32位版本:AmtApiWrapper32.dll

64位调试:AmtApiWrapper64d.dll

64位版本:AmtApiWrapper64.dll

这些包装器是一个单独的C++项目,它包装了我编写的C Native DLL.C/C++是我平常的平台,所以如果这是一个小问题,请原谅.

所有包装器DLL都包含完全相同的函数和相同的原型.除了这个之外,它们还用于许多其他目的,所以除非这非常糟糕,否则设置保持不变.

所以,我想在编译时加载其中一个.我已经查看了诸如反射,GetDelegateForFunctionPointer和其他一些东西之类的东西,它们看起来很相似,但对于这个简单的任务来说过于复杂.有什么建议?谢谢

Jon*_*eet 6

这绝对是可能的,但你必须涉足构建文件.

你想要的东西是这样的:

<ItemGroup Condition=" '$(Configuration)' == '32-bit debug' ">
  <Reference Include="AmtApiWrapper32d">
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == '32-bit release' ">
  <Reference Include="AmtApiWrapper32">
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == '64-bit debug' ">
  <Reference Include="AmtApiWrapper64d">
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == '64-bit release' ">
  <Reference Include="AmtApiWrapper64">
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)

我建议你无条件地让其中一个工作,然后看看参考的确切内容.

如果您想将其添加为构建时引用,那就是这样.如果要在P/Invoke声明中使用它,只需在相应的属性周围使用#if SYMBOL/ #endif.