Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading different assemblies at compile-time based on Build Target

I want to load one of four separate C# assemblies based upon what the build target is. This is going into a webservice with .net framework 3.0.

possibilities:

32-bit debug: AmtApiWrapper32d.dll

32-bit release: AmtApiWrapper32.dll

64-bit debug: AmtApiWrapper64d.dll

64-bit release: AmtApiWrapper64.dll

Those wrappers are a separate C++ project that wrap a C Native DLL that I wrote. C/C++ is my usual platform so please excuse me if this is a nubs question.

All of the wrapper DLLs contain the exact same functions and same prototypes. They're used for many other purposes besides this one, so unless this is really terrible, the setup stays the same.

So, i want to load one of them at compile time. I've looked over stuff like reflection, GetDelegateForFunctionPointer, and some other stuff, and they all seem similar but overly complicated for this simple task. Any suggestions? THANKS

like image 600
rajat banerjee Avatar asked Jan 28 '09 20:01

rajat banerjee


1 Answers

It's definitely possible, but you'll have to wade into the build file.

You'd want something like:

<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>

I suggest you unconditionally get one of them working, and then look at exactly what the reference looks like.

That's if you want to add it as a build-time reference. If you want to use it in a P/Invoke declaration, just use #if SYMBOL/#endif around the appropriate attribute.

like image 128
Jon Skeet Avatar answered Oct 01 '22 11:10

Jon Skeet