Kar*_*ann 5 c# wpf dll merge fluent
我的问题是关于一个Fluent,我program.exe
使用此代码与我在一个merged.exe中合并:
public class Program
{
[STAThreadAttribute]
public static void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
App.Main();
}
private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
{
//We dont' care about System Assemblies and so on...
//if (!args.Name.ToLower().StartsWith("wpfcontrol")) return null;
Assembly thisAssembly = Assembly.GetExecutingAssembly();
//Get the Name of the AssemblyFile
var name = args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll";
//Load form Embedded Resources - This Function is not called if the Assembly is in the Application Folder
var resources = thisAssembly.GetManifestResourceNames().Where(s => s.EndsWith(name));
if (resources.Count() > 0)
{
var resourceName = resources.First();
using (Stream stream = thisAssembly.GetManifestResourceStream(resourceName))
{
if (stream == null) return null;
var block = new byte[stream.Length];
stream.Read(block, 0, block.Length);
return Assembly.Load(block);
}
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是Fluent Ribbon Control无法找到任何样式,但我在app.xaml中使用它们来解决它
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Office2010/Silver.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
我使用此解决方案的第二个问题是,当我在没有Visual Studio的情况下启动它时,我无法使用我的程序连接到我的数据库(SQL Express).
当我在同一个文件夹中使用它时,它就可以正常工作,因为它不会从嵌入式引用的流利中加载它.而Fluent也可以找到这种风格.
有没有人有类似dll/fluent合并到main.exe的经验,你能告诉我你是如何解决它的吗?
使用 Fody.Costura 代替,这对我有用(我也使用 Fluent)。
https://github.com/Fody/Costura
重要的事情之一是让您的应用程序知道它必须加载程序集。我有时会在应用程序启动时强制加载:
Console.WriteLine(typeof(Fluent).Name);