c# - Fluent合并到main.exe后出现的问题

标签 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;
        }
    }

我的问题是 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>

此解决方案的第二个问题是,当我在没有 Visual Studio 的情况下启动它时,我无法使用我的程序连接到我的数据库 (SQL Express)。

当我在同一个文件夹中有流利时,它就可以工作,因为那样它就不会从嵌入式引用的流利中加载它。 Fluent 也能找到风格。

有没有人有类似的将 dll/fluent 合并到 main.exe 的经验,你能告诉我你是如何解决的吗?

最佳答案

改用 Fody.Costura,这对我有用(我也使用 Fluent)。

https://github.com/Fody/Costura

其中一件重要的事情是让您的应用程序知道它必须加载程序集。我有时会在您的应用启动时强制加载:

Console.WriteLine(typeof(Fluent).Name);

关于c# - Fluent合并到main.exe后出现的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18328483/

相关文章:

wpf - 设置 ItemsControl 中第 N 个项目的样式

c++ - DLL的Class的方法的使用

c++ - 使用 dumpbin 显示 DLL 的外部符号(UNDEF)?

c# - 为什么在 C# 中使用 Neo4j 时 'IDriver' 不包含 'Session' 的定义?

c# - CookieContainer 不保存所有 cookie

c# - 如何在wpf中聚焦选项卡

wpf - Expression Blend 和 Visual Studio 渲染 WPF 控件的方式是否不同

c++ - 在全屏模式游戏中运行exe文件

c# - 如何在c#中反序列化json数组

c# - 在字符串中使用数组