I'm having a really hard time bundling all of my dependencies in my C# WPF project into a single exe, using SmartAssembly 6 (evaluation/trial), because of MahApps.Metro.
This conclusion was drawn when creating a completely empty project with nothing but MahApps.Metro, and still not being able to bundle it.
It throws an exception with an inner exception System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I've spent a day and a half trying to resolve this, Googling the error, trying every suggestion I can find, and posting in the official MahApps.Metro chat (https://gitter.im/MahApps/MahApps.Metro). I've tried all kinds of variation where I removed System.Windows.Interactivity dll, added it, moved it to another path, etc.
Using the latest MahApps.Metro package from NuGet, and .NET 4.5. The program works when I run it from Visual Studio 2012, or when I run the application from Debug/Release.
Has anyone ever encountered this problem before? How did you resolve it? Is the problem the bundle application (SmartAssembly 6) or MahApps.Metro? Are there any other bundle programs that you know, or think, will work with MahApps.Metro?
here is my way to put the dlls in a single exe
1) create a folder named DllsAsResource
and put the MahApps.Metro.dll
and System.Windows.Interactivity.dll
with Add as Link
to it
2) change the Build Action
for the dlls to Embedded Resource
3) change Copy Local
to false
for the normal referenced dlls
4) create Program.cs
using System;
using System.Reflection;
namespace MahApps.Metro.Simple.Demo
{
public class Program
{
[STAThread]
public static void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
var resourceName = Assembly.GetExecutingAssembly().GetName().Name + ".DllsAsResource." + new AssemblyName(args.Name).Name + ".dll";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) {
if (stream != null) {
var assemblyData = new Byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
}
}
return null;
};
App.Main();
}
}
}
5) set the Startup object
to the Program.cs
in your project properties
6) now you have a single exe without publishing the hole dlls
you can look at this demo for all the tips
hope that helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With