Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static linking in C#?

The Windows Azure client libraries are very big (several MBs), and I have a fairly small project (on the order of a few hundred KBs) that uses only a few functions from them. Is there a way for me to link in those functions at build time, so that the resultant DLL doesn't get hugely bloated, and I don't have to link the functions in at runtime?

Something like this http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx, but I get the impression that bundles in the whole DLL.

Thanks!

Edit: Because there are external constraints on the size of the final deliverable DLL, inflating it this much is an absolute last resort - the only other option I'm aware of is just to duplicate the code I use verbatim.

like image 828
bfops Avatar asked Sep 24 '14 01:09

bfops


2 Answers

In a word: No.

Remember that even though you only use a few functions, there are likely many other function in the library that those functions use, that you don't even know about!

You can't do this, because you don't have access to all the dependencies. Remember also that those dependencies may even reside in another DLL, and you need to include that entire DLL for the same reason.

like image 180
BradleyDotNET Avatar answered Sep 21 '22 12:09

BradleyDotNET


What you are looking for sounds very like .NET Native. Unfortunately for you, its only preview and right now works only with Store Apps for devices. Statements like this

We will continue to evolve and improve native compilation for the range of .NET applications

can be found on the internet but nothing specific about web apps\Azure.

Until then, answer is No

like image 22
Michal Levý Avatar answered Sep 19 '22 12:09

Michal Levý