Click here to Skip to main content
16,019,018 members
Articles / Programming Languages / C#
Article

Merging DLLs into Your Main Assembly for Easier Distribution

2 Apr 2012CPOL2 min read 50.3K   19   16
Distributing applications with DLL dependencies can be problematic. Here we explain how to make distribution easier by combining these dependencies into the main assembly.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Compiling .NET code often results in multiple assembly files being created, including satellite DLLs, all of which are required for the program to run. While this is a non-issue during development, when it comes to deployment it often means an unwanted stage of users having to unzip files, or manually move certain DLLs to specific places.

SmartAssembly is capable of merging the code from referenced DLLs into the main assembly, producing a single application for deployment and so greatly simplifying the process.

When merging dependencies, SmartAssembly completely integrates the dependency code into the main assembly code. Instead of making public calls (by name), the resulting assembly instead makes internal calls by Member ID. As well as making deployment easier, this also provides some level of protection against people examining and reverse-engineering sensitive code.

Merging referenced DLLs is a simple process. After adding the main assembly to a project as the input, and selecting an output destination, SmartAssembly automatically scans for dependencies and presents a list. We select the DLLs we wish to merge and click ‘Build’ to generate the output file.

Merging-DLLs/image001.png

Figure 1: Merging assemblies with dependencies in SmartAssembly

There are some limitations to what can be successfully merged. For example, some third-party DLLs will include integrity protection, which causes the DLL to fail to load as its contents will appear to have been modified.

For these instances, SmartAssembly supports dependency embedding, which allows referenced DLLs to be embedded into the main assembly as resources, instead of being merged into the main assembly’s contents. It is also capable of compressing these resources and dynamically uncompressing them at runtime, significantly reducing the distributed file size.

Merging-DLLs/image002.png

Figure 2: The difference between merging and embedding assemblies

As well as merging and embedding dependencies, SmartAssembly can apply powerful obfuscation to assemblies, preventing malicious users from decompiling them. It can also add Automated Error Reporting, a sophisticated mechanism for receiving reports of any unhandled exceptions which occur when your application is used in the wild, along with all the data needed to diagnose them.

SmartAssembly can be controlled through the command-line, so it is easily integrated into the build process, providing simple, reliable merging of dependencies on every build.

Learn more about SmartAssembly, or download your free trial.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Red Gate Software Ltd.
United Kingdom United Kingdom
Redgate makes ingeniously simple software used by 804,745 IT professionals and counting, and is the leading Microsoft SQL Server tools vendor. Our philosophy is to design highly usable, reliable tools which elegantly solve the problems developers and DBAs face every day, and help them adopt database DevOps. As a result, more than 100,000 companies use products in the Redgate SQL Toolbelt, including 91% of those in the Fortune 100.
This is a Organisation

1 members

Comments and Discussions

 
QuestionSmartAssembly Doesn't seem work perfectly. Pin
VijayBabuM8-Jul-12 8:48
VijayBabuM8-Jul-12 8:48 
QuestionILMerge Pin
crashedapp31-Jan-12 4:46
crashedapp31-Jan-12 4:46 
AnswerRe: ILMerge Pin
slaphead993-May-12 4:31
slaphead993-May-12 4:31 
Questiontry .netshrink Pin
Bartosz Wójcik22-Jan-12 23:57
Bartosz Wójcik22-Jan-12 23:57 
AnswerRe: try .netshrink Pin
slaphead993-May-12 4:37
slaphead993-May-12 4:37 
GeneralRe: try .netshrink Pin
Bartosz Wójcik4-May-12 23:15
Bartosz Wójcik4-May-12 23:15 
GeneralRe: try .netshrink Pin
slaphead995-May-12 10:10
slaphead995-May-12 10:10 
GeneralRe: try .netshrink Pin
Bartosz Wójcik5-May-12 11:36
Bartosz Wójcik5-May-12 11:36 
GeneralRe: try .netshrink Pin
slaphead995-May-12 11:46
slaphead995-May-12 11:46 
GeneralRe: try .netshrink Pin
Bartosz Wójcik5-May-12 12:36
Bartosz Wójcik5-May-12 12:36 
GeneralRe: try .netshrink Pin
Member 89433458-May-12 0:31
Member 89433458-May-12 0:31 
Generalwe do it too by hand Pin
CarelAgain13-Jan-12 5:38
professionalCarelAgain13-Jan-12 5:38 
GeneralRe: we do it too by hand Pin
Member 405342422-Jan-12 21:10
Member 405342422-Jan-12 21:10 
GeneralRe: we do it too by hand Pin
psmacchia22-Jan-12 21:31
psmacchia22-Jan-12 21:31 
QuestionUnmanaged DLLs? Pin
Marc Bernier12-Jan-12 7:09
Marc Bernier12-Jan-12 7:09 
AnswerRe: Unmanaged DLLs? Pin
slaphead993-May-12 4:39
slaphead993-May-12 4:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.