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?
4 Answers
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);
Comments
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)