2014-07-10 55 views
1

我想導入嵌入到我的EXE的DLL的命名空間。 我使用WPFtoolkit此應用程序,所以我的XAML正在訪問的命名空間是這樣的:導入第三方命名空間(的嵌入式DLL)到XAML

<Window 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" x:Class="Imperium.MainWindow" 
     Title="Imperium" Height="435" Width="510" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Icon="pack://application:,,,/ExtFiles/Imp.ico" Closing="Window_Closing" MouseDown="Grid_MouseDown" WindowStyle="None" BorderThickness="1" BorderBrush="Black" Foreground="Black"> 

它正常工作與DLL被複制到本地。但是我希望將這兩個DLL嵌入到我的EXE中。兩個DLL之一(WPFToolkit.dll)是沒有問題的,因爲它不是在XAML中引用的,所以我使用的解決方案(請參閱http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/comment-page-1/#comment-818對此工作正常)。

但是,第二個DLL(system.windows.controls.datavisualization.toolkit.dll)給我帶來麻煩。

任何想法我可以做到這一點?

謝謝 史蒂夫

編輯:讓我澄清一點:

我的應用程序有2個DLL的,我能夠在EXE同時嵌入(文件大小顯示在那裏),並且其中一個被稱爲很好(僅在使用時調用)。

另一個被稱爲XAML名稱空間導入 - 當我運行該程序時出現錯誤。

這裏是我的App.g.cs

public static void Main() { 
      AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly; //aded 
      Swiftech_Imperium.App app = new Swiftech_Imperium.App(); 
      app.InitializeComponent(); 
      app.Run(); 
     } 

     // added 
     private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args) 
     { 
      Assembly executingAssembly = Assembly.GetExecutingAssembly(); 
      AssemblyName assemblyName = new AssemblyName(args.Name); 

      string path = assemblyName.Name + ".dll"; 
      if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false) 
       path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path); 
      using (Stream stream = executingAssembly.GetManifestResourceStream(path)) 
      { 
       if (stream == null) 
        return null; 
       byte[] assemblyRawBytes = new byte[stream.Length]; 
       stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length); 
       return Assembly.Load(assemblyRawBytes); 
      } 
     } 

看到帖子的XAML的開始。

這兩個DLL的設置操作都是「嵌入資源」。

我用這個「教程」:http://www.digitallycreated.net/Blog/61/combining-multiple-assemblies-into-a-single-exe-for-a-wpf-application

我沒能找到地方放了在本教程中提到的XAML(目標),所以這可能是爲什麼它不工作。

我使用VS 2013快,它也許我爲什麼不能找一下筆者指的是:

(this code snippet should be added to your project file underneath where the standard Microsoft.CSharp.targets file is imported): 
+0

有沒有人有想法?該DLL很好嵌入,但不幸的是,調用它的XAML的一部分找不到它。 – user3617652

回答

0

我知道這是遲到的回答,但我想通了自己。您需要使用外部文本編輯器實際打開項目文件,並將鏈接教程中提供的內容粘貼到文件末尾。

這應該解決您的問題。