Jump to content

Package all dependencies into one DLL (C#)

RileyTheFox
Go to solution Solved by straight_stewie,
4 hours ago, FlappyBoobs said:

Thats not correct. If you build them as embedded resources then it is possible. 

Almost all of the responses in that StackOverflow thread are about dynamic .dll loading, using the CLRs Appdomain.AssemblyResolve event that fires after the CLR is unable to find a dependency.

This requires startup code to work, and may be very slow, both because those solutions only run after the CLR fails to find an assembly (one that the developer already knows for sure it won't find), and because it relies on some serious reflection to load the .dlls in.
 

23 hours ago, RileyTheFox said:

is there any way I can include those dependencies into the DLL so I don't need to distribute loads of other dependencies (and their dependencies, then their dependencies etc)

There is a tool called ILMerge. It is a static linker for dotnet, which is exactly what you are asking for.

Hi. I'm writing a Class Library in C# and it depends on some external DLL files, is there any way I can include those dependencies into the DLL so I don't need to distribute loads of other dependencies (and their dependencies, then their dependencies etc). Is there any way to do this in the visual studio build process?

 

Thanks.

CPU: Intel Core i7 8700  

GPU: Gigabyte GeForce GTX 1070

MOBO: ASUS Z370-F STRIX  

RAM: 16GB Corsair Vengeance DDR4 2133MHz

Link to comment
Share on other sites

Link to post
Share on other sites

In Visual Studio just reference the dlls in your project. When it is built into a library it will include all of the referenced libraries as well. 

Link to comment
Share on other sites

Link to post
Share on other sites

No, it's not possible. If you're building a .NET Core app, you can publish a self-contained executable, which will serve the end goal of not having to transport all these DLLs individually, but not as a class library alone.

CPU: AMD Ryzen 9 5900X · Cooler: Artic Liquid Freezer II 280 · Motherboard: MSI MEG X570 Unify · RAM: G.skill Ripjaws V 2x16GB 3600MHz CL16 (2Rx8) · Graphics Card: ASUS GeForce RTX 3060 Ti TUF Gaming · Boot Drive: 500GB WD Black SN750 M.2 NVMe SSD · Game Drive: 2TB Crucial MX500 SATA SSD · PSU: Corsair White RM850x 850W 80+ Gold · Case: Corsair 4000D Airflow · Monitor: MSI Optix MAG342CQR 34” UWQHD 3440x1440 144Hz · Keyboard: Corsair K100 RGB Optical-Mechanical Gaming Keyboard (OPX Switch) · Mouse: Corsair Ironclaw RGB Wireless Gaming Mouse

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, FlappyBoobs said:

Thats not correct. If you build them as embedded resources then it is possible. 

Almost all of the responses in that StackOverflow thread are about dynamic .dll loading, using the CLRs Appdomain.AssemblyResolve event that fires after the CLR is unable to find a dependency.

This requires startup code to work, and may be very slow, both because those solutions only run after the CLR fails to find an assembly (one that the developer already knows for sure it won't find), and because it relies on some serious reflection to load the .dlls in.
 

23 hours ago, RileyTheFox said:

is there any way I can include those dependencies into the DLL so I don't need to distribute loads of other dependencies (and their dependencies, then their dependencies etc)

There is a tool called ILMerge. It is a static linker for dotnet, which is exactly what you are asking for.

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

10 hours ago, straight_stewie said:

 There is a tool called ILMerge. It is a static linker for dotnet, which is exactly what you are asking for.

Which is the tool mentioned in the link I posted. 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 8 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×