Last updated on 27 June 2020
If you ever made a program in C#, or are planning to do so, there is a chance that you’ve used NuGet packages to make your development easier. An example of this would be Ndesk.options to deal with command line argument parsing.
The problem with this approach is that your assembly now has dependencies. And dependencies don’t play well when you want to execute your assemblies in an unmanaged loader.
There are a few options to bundle your dependencies in your assembly, so that these are actually embedded in your own assembly, eliminating the dependency (but bloating your own assembly, which is A-OK for our purposes).
The easiest way to do this is by using https://github.com/Fody/Costura
Which is.. a NuGet Package on it’s own! 🙂
Basically all you have to do is include it in your project by going to
project -> manage NuGet Packages. Browse the NuGet Gallery and choose Costura.Fody to include it in your project.
Once this is done, build your project and Costura will generate two new files that are not included in your project solution by default, you’ll have to include those manually. (Fodyweavers.xml and .xsd) include those in your project and build it once again.
Now your assembly will be able to stand alone without any external dependencies! (making it compatible with unmanaged CLR loaders).
Gotcha, The latest Costura.Fody requires .NET 4.0, if you need .NET 3.5 be sure to use costura 1.6.2, instead of latest.
For more in depth details and suggestions on how to embed dependencies in your assembly, see this post of the almighty Cobbr
Be First to Comment