Embed referenced assemblies, because ILMerge won't work with WPF applications
public partial class App : Application { | |
public App() { | |
AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly; | |
} | |
private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args) { | |
var executingAssembly = Assembly.GetExecutingAssembly(); | |
var 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 (var 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); | |
} | |
} | |
} |
<?xml version="1.0" encoding="utf-8" ?> | |
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<!-- | |
Originally written by Daniel Chambers (http://www.digitallycreated.net) | |
http://www.digitallycreated.net/Blog/61/combining-multiple-assemblies-into-a-single-exe-for-a-wpf-application | |
--> | |
<Target Name="EmbedReferencedAssemblies" AfterTargets="ResolveAssemblyReferences"> | |
<ItemGroup> | |
<!-- get list of assemblies marked as CopyToLocal --> | |
<AssembliesToEmbed Include="@(ReferenceCopyLocalPaths)" Condition="'%(Extension)' == '.dll'"/> | |
<!-- add these assemblies to the list of embedded resources --> | |
<EmbeddedResource Include="@(AssembliesToEmbed)"> | |
<LogicalName>%(Filename)%(Extension)</LogicalName> | |
</EmbeddedResource> | |
<!-- no need to copy the assmblies locally anymore --> | |
<ReferenceCopyLocalPaths Remove="@(AssembliesToEmbed)"/> | |
</ItemGroup> | |
<Message Importance="high" Text="Embedding: @(AssembliesToEmbed->'%(Filename)%(Extension)', ', ')"/> | |
</Target> | |
</Project> |
This comment has been minimized.
This comment has been minimized.
Originally written by Daniel Chambers, see Combining multiple assemblies into a single EXE for a WPF application |
This comment has been minimized.
This comment has been minimized.
Originally written by Daniel Chambers, see Combining multiple assemblies into a single EXE for a WPF application |
This comment has been minimized.
This comment has been minimized.
Originally written by Daniel Chambers, see Combining multiple assemblies into a single EXE for a WPF application |
This comment has been minimized.
This comment has been minimized.
Nice snippet. Just one suggestion, this block:
can be replaced by simply removing the
This will also prevent from copying |
This comment has been minimized.
This comment has been minimized.
I edited EmbeddedResource action a bit. So it will properly handle localized dlls:
You have all the necessary code in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Originally written by Daniel Chambers, see Combining multiple assemblies into a single EXE for a WPF application