Possible solutions:
Merge builds into one after compilation
Several assemblies can be glued to one after compilation using the ILMerge utility.
She is on NuGet.org :
Install-Package ilmerge
Call format:
ilmerge /lib:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319" /lib:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies" /targetplatform:v4 /out:out.dll mydll1.dll mydll2.dll
before using the path it is worth correcting for the current
Similar utilities - il-repack , Mono.Merge
Inclusion of DLL in EXE in the form of Embedded Resource with the substitution of the standard loading mechanism:
- Add
bin\someassembly.dll to exe project via Add Existing Item / arrow on Add / Add as Link, set Build Type = Embedded Resource - Add
someassembly project to References. Set reference to Copy Local = false - to avoid copying to bin. Process CurrentDomain_AssemblyResolve :
using System; using System.Reflection; using System.Windows.Forms; namespace WindowsFormsApplication7 { static class Program { [STAThread] static void Main() { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { var assemblyName = new AssemblyName(args.Name).Name; if (assemblyName == "someassembly") { using (var stream = typeof(Program).Assembly.GetManifestResourceStream( "WindowsFormsApplication7." + assemblyName + ".dll")) { byte[] assemblyData = new byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); return Assembly.Load(assemblyData); } } else { return null; } } } }
This is a minimal working example. If it does not work, run under the debugger. Most likely you did not guess with the name of the resource, and GetManifestResourceStream returns null . Make sure that the type of the item is set in the Embedded Resource (and not just in the Resource). You can view the names of all available resources directly in the debugger, by calling
typeof(Program).Assembly.GetManifestResourceNames()
The project entirely on githaba, on the example of SevenZipSharp: https://github.com/PashaPash/SevenZipSharp-Embedded
Enable assemblies as resources, automatic option
Install the Costura.Fody package via nuget and get one exe on exit.
> PM> Install-Package Costura.Fody
Alternatives: