Reputation:
I am looking for the equivalent of C++'s #pragma comment(lib, "name"); but for C# and adding assembly references. How can i do it?
Upvotes: 1
Views: 1542
Reputation: 51548
If I understand correctly, you can use PInvoke through [DLLImport] as in the example below:
[DllImport("User32.dll", SetLastError=true)]
static extern Boolean MessageBeep(UInt32 beepType);
Upvotes: 1
Reputation: 74702
You can't do this, because the C# compiler needs the reference beforehand to be able to generate the IL, whereas the C++ compiler has header files that describe the layout of the referenced libraries (at least from a parser/verification perspective - it needs the LIB in the generation phase to actually be able to write the offsets)
Upvotes: 0
Reputation: 136673
Don't think you can dynamically add a reference via code.
However you could load the needed assembly via Reflection in code (Assembly.LoadXXX methods) and then access the types defined in it.
Upvotes: 2