Compile .NET Framework class library with NuGets to single DLL [Answered]
I have a .NET Framework 4.8.1 (unable to upgrade) class library which references a number of NuGet packages. I would like to compile this library to a single, self-contained DLL file. Is this possible? How?
4 Replies
Hm, Costura.Fody seems to work. Is there another way? It kinda bloats my library with a bunch of NuGets that I don't even use.
✅ This post has been marked as answered!
so, let me try to cover what happened
i'm trying to create a .NET Framework class library for a program which allows a sort of plugin-system. what it does is load specified DLL files and then interacts with their code
this means that i have (almost) free reign about what i put into that library. it's obviously sandboxed, only allowing specific calls to interact with the program
now, unfortunately this system means that i cannot actually use any NuGets or other referenced libraries in my own plugin
the reason is that calling any methods or using any types from those libraries will result in a
FileNotFoundException
for the target assembly
i was hoping i could compile my plugin to a single file with all references embedded
i was playing around with this yesterday, trying out different combinations of CLI commands, csproj tags, Costura, and ILMerge
and for some odd reason, i was eventually able to simply compile, and the FileNotFoundException
s would simply not throw at all anymore
without Costura, and without ILMerge
unfortunately i wasn't smart enough to use source control, and i fiddled around a bit with the solution and project settings, and it broke again
and i have absolutely no clue how this worked in the first place
does anyone have even the slightest idea?
yeah so i just added the Costura.Fody nuget package, compiled my project, and removed it again, and now all my referenced types are embedded...
no idea what's going on✅ This post has been marked as answered!