Library:Costura.Fody
| On this wiki | Facts · Code · Notes · Topics |
|---|
Fody add-in that embeds a .NET program's dependencies as resources named costura.<name>.dll(.compressed) and adds a resolver that loads them at start-up; recognise it by those resource names, a costura.metadata resource and an AssemblyLoader class, then extract the resources (raw DEFLATE) to get the original assemblies.
Costura (Fody add-in, MIT) is an IL weaver run at build time: it copies dependency DLLs (and optionally PDBs) into the main assembly as managed resources and injects code that resolves missing assemblies from them (AppDomain.AssemblyResolve). The README declares the package in maintenance mode since .NET Core 3 single-file publishing (Format:.NET single-file bundle). Common in small Windows tools, so a .NET exe with almost no DLLs next to it is often Costura-packed.
Recognition
- Manifest resources whose names start with
costura(Fact:Costura.Fody/behavior/Resource naming):costura.<lowercase file name>.dll(managed, uncompressed) orcostura.<name>.dll.compressed(default: compressed);.pdbversions likewise;costura.metadatalists the embedded items (checksums). - Native libraries: prefixes
costura_win_x86.,costura_win_x64.,costura_win_arm64.(older:costura32.,costura64.), unmanaged and loaded from a temp folder. - Satellite assemblies are embedded with the name
<assembly>.resourcesin the costura. naming scheme (ResourceEmbedder.cs lines 280 and 389 build that name). - Injected type in the module:
Costura.AssemblyLoader. The weaver (Fody/Costura commit f2b799eb539226f12efcd2b815cfa139c833daa5, src/Costura.Fody/AssemblyLoaderImporter.cs line 78) creates it as a copy of the template classILTemplateand copies its methodsResolveAssembly(line 85) andAttach(line 87); in src/Costura.Template/ILTemplate.csAttach(bool subscribe)hooksAssemblyLoadContext.Default.ResolvingorAppDomain.AssemblyResolvetoResolveAssembly(lines 20-41), and the shared helpersReadFromEmbeddedResources,ReadFromDiskCacheandPreloadUnmanagedLibrarieslive in src/Costura.Template/Common.cs (lines 118-218). Unverified: how the call toAttachis placed in the woven module (module initializer or static constructor).
Extraction
A .compressed resource is (Common.cs line 206 wraps the manifest resource stream in a DeflateStream in decompress mode) a raw DEFLATE stream (System.IO.Compression.DeflateStream, no zlib header) of the whole file; an uncompressed one is the file itself. Save the resource from ILSpy / dnSpyEx, or read it with a metadata parser such as Code:.NET metadata (ECMA-335)/dotnetmd (Python), and inflate with zlib wbits=-15. Unverified: that dotnetmd can export arbitrary resources.
The embedded assemblies are normal Format:.NET metadata (ECMA-335) PEs; analyse them as the program's real dependencies. Other tools that merge assemblies (ILMerge, ILRepack) copy the types into the main module instead and leave no such resources.
Code & repositories
- https://github.com/Fody/Costura @
f2b799eb539226f12efcd2b815cfa139c833daa5· license: MIT
Costura.Fody (MIT): the weaver (src/Costura.Fody) and the injected loader template (src/Costura.Template).
Tested on: source read, not run: Read the source at this commit; nothing run. · checked 2026-10-18; last activity 2026-10-18
Evidence & references
Fody/Costura commit f2b799e (see link): src/Costura.Fody/ResourceNameFinder.cs, ResourceEmbedder.cs, src/Costura.Template/Common.cs, readme.md.