Merging dlls into a single .exe with wpf
This worked like a charm for me :) and its completely free.
Adding code in case the blog ever disappears.
1) Add this to your .csproj
file:
<Target Name="AfterResolveReferences"> <ItemGroup> <EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll'"> <LogicalName>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName> </EmbeddedResource> </ItemGroup></Target>
2) Make your Main Program.cs
look like this:
[STAThreadAttribute]public static void Main(){ AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly; App.Main();}
3) Add the OnResolveAssembly
method:
private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args){ Assembly executingAssembly = Assembly.GetExecutingAssembly(); AssemblyName assemblyName = new AssemblyName(args.Name); var path = assemblyName.Name + ".dll"; if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false) path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path); using (Stream stream = executingAssembly.GetManifestResourceStream(path)) { if (stream == null) return null; var assemblyRawBytes = new byte[stream.Length]; stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length); return Assembly.Load(assemblyRawBytes); }}
{smartassembly} is one such product. It can obsfucate or embedd your dlls.
Try this: http://www.smartassembly.com/
You can also do a lot of improvements on your application so it will run faster.
And yes. You can use it for WPF.
Update 8/06/2015:ILRepack 2.0.0 (which is an open-source alternative to ILMerge) has now support for most of WPF cases merging: https://twitter.com/Gluckies/status/607680149157462016