2013-08-20 1 views
5

私の質問に流暢マージした後、私はこのコードで1 merged.exeで私program.exeと合併Fluent、についてです:問題MAIN.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; 
     } 
    } 

私の問題は、流暢リボンコントロールを見つける傾けることです任意のスタイル、私app.xamlで、私は彼らとそれを解決したコード

<Application.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/Office2010/Silver.xaml" /> 
      </ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Application.Resources> 

私は、このソリューションを持っている第二の問題は、私はそれを起動したとき、私は私のプログラムで私のデータベース(SQLエクスプレス)に接続傾けることですVisual Studioなし。

私は同じフォルダに流暢ですが、うまくいきました。なぜなら、埋め込まれた流暢な参照から読み込まないからです。そしてFluentもスタイルを見つけることができます。

誰もがmain.exeにdll/fluentをマージするのに似た経験を持っていますが、あなたはそれをどのように解決したかを教えてください。

+1

だから、アプリケーションに*リソース*としてアセンブリを追加し、それを実行時にロードしていますか?単にそれを**リファレンス**として追加し、 'Copy Local'をtrueに設定するのはなぜですか? –

答えて

1

代わりにFody.Costuraを使用してください。これは私にとってはうまくいきます(またFluentも使用します)。重要なことの

https://github.com/Fody/Costura

つのアプリは、それがアセンブリをロードする必要があることを知らせることです。読み込みを強制するために私が時々行うことは、あなたのアプリケーションの起動時にこれがあります:

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