ILMerge: Combinare gli Assembly in un UNICO Output

Lo scorso anno ho avuto l’esigenza di scrivere un tool per un cliente e durante la fase di sviluppo mi ero posto un posto un problema di base: Perché una volta finito lo sviluppo devo consegnarmi anche le mie dll con tutti i miei componenti scritti? La risposta è arrivata con una serie di ricerche in google e si chiama ILMerge.

ATTENZIONE: Se utilizzate NETCore vi consiglio di leggere NetCore: Effettuare il publish del solo eseguibile

ILMerge: Chi sei?

ILMerge è una fantastica utility che ha lo scopo di unire in un solo output tutti i propri assembly scritti in un progetto. Detto così è veramente uno spettacolo, ma ora vediamo quache dettaglio in più. Di seguito riporto la descrizione presente quando si installa il pacchetto tramite NuGet:

ILMerge is a utility that can be used to merge multiple .NET assemblies into a single assembly. ILMerge takes a set of input assemblies and merges them into one target assembly. The first assembly in the list of input assemblies is the primary assembly. When the primary assembly is an executable, then the target assembly is created as an executable with the same entry point as the primary assembly. Also, if the primary assembly has a strong name, and a .snk file is provided, then the target assembly is re-signed with the specified key so that it also has a strong name. ILMerge is packaged as a console application. But all of its functionality is also available programmatically. There are several options that control the behavior of ILMerge. See the documentation that comes with the tool for details.

Per installarlo abbiamo due possibilità:

  • La prima è quella di scaricarlo dal sito della Microsoft nella pagina ILMerge.

  • Internamente da Visual Studio basta aprire il gestore dei pacchetti Nuget e cercarlo al suo interno. Nuget Gallery | ILMerge

Per maggiori informazioni sul progetto vi suggerisco di leggere la sezione specifica sulla home di " Mike Barnett” (Principal Research Software Design Engineer) ideatore del progetto.

ILMerge: Come usarlo?

Usare ILMerge non è difficile e ci sono diverse possibilità per farlo. Modalità Diretta

1
2
3

ilmerge /out:<nomefinale>.dll <PrimaryAssembly>.dll <Secondary1Assembly>.dll <Secondary2Assembly>.dll

Modalità WildCards

1
2
3

ilmerge  /wildcards /out:<nomefinale>.dll <PrimaryAssembly>.dll <Secondary*Assembly>.dll 

Modalità Logger

1
2
3

ilmerge  /log /wildcards /out:<nomefinale>.dll <PrimaryAssembly>.dll <Secondary*Assembly>.dll 

ILMerge: Solo testuale?

Non vi piace utlizzare la linea di comando e preferite usare -da utenti windows- le applicazioni in modalità grafica? State tranquilli, esiste anche un tool per ottenere lo stesso risultato, ma senza dovere ricordare la sintassi. Si chiama ILMergeGUI e la potete scaricare dalla pagina ufficiale del progetto " ilmergegui

ILMerge: Conviene?

Conviene davvero usare ILMerge? A mio avviso SI! Personalmente metto uno dei comandi appena descritti come azione di post build in Visual Studio. In questo modo, una volta lanciata la compilazione ho automaticamente il prodotto finale.