C# 嵌入DLL和引用XAML
我有一个使用GMAP.Net和扩展WPF工具包的WPF应用程序。我直接在XAML中引用这些库中的控件。我想将这些DLL添加到我的项目中,并将它们标记为嵌入式资源 当我不再使用dll作为引用时,如何继续引用XAML中的控件 编辑:没有太多代码显示。当我使用gmap作为参考时,这是有效的C# 嵌入DLL和引用XAML,c#,wpf,xaml,C#,Wpf,Xaml,我有一个使用GMAP.Net和扩展WPF工具包的WPF应用程序。我直接在XAML中引用这些库中的控件。我想将这些DLL添加到我的项目中,并将它们标记为嵌入式资源 当我不再使用dll作为引用时,如何继续引用XAML中的控件 编辑:没有太多代码显示。当我使用gmap作为参考时,这是有效的 xmlns:WindowsPresentation="clr-namespace:GMap.NET.WindowsPresentation;assembly=GMap.NET.WindowsPresentation
xmlns:WindowsPresentation="clr-namespace:GMap.NET.WindowsPresentation;assembly=GMap.NET.WindowsPresentation"
删除gmap作为引用并添加为嵌入资源后出现错误消息:
错误1命名空间“clr命名空间:GMap.NET.WindowsPresentation;assembly=GMap.NET.WindowsPresentation”中不存在名称“GMapControl”。Windows\MapWindow.xaml
xmlns
intelissense/下拉列表中不存在gmap引用保留引用的DLL,只是在构建最终版本时不要复制它们。另外,您是否向AssemblyResolve添加了代码以拉入嵌入的资源?我的代码使用gzip程序集
AppDomain.CurrentDomain.AssemblyResolve += ( sender, args ) =>
{
try
{
String resourceName = String.Format( "Program.Libs.{0}.dll.gz", new AssemblyName( args.Name ).Name );
using (var stream = new GZipStream( Assembly.GetExecutingAssembly().GetManifestResourceStream( resourceName ), CompressionMode.Decompress ))
using (var outstream = new MemoryStream())
{
CopyTo( stream, outstream );
return Assembly.Load( outstream.GetBuffer() );
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine( e.ToString() );
return null;
}
};
public static long CopyTo( Stream source, Stream destination )
{
byte[] buffer = new byte[ 2048 ];
int bytesRead;
long totalBytes = 0;
while ((bytesRead = source.Read( buffer, 0, buffer.Length )) > 0)
{
destination.Write( buffer, 0, bytesRead );
totalBytes += bytesRead;
}
return totalBytes;
}
你试过什么吗?我已经从我的引用列表中删除了dll,并将它们作为嵌入资源添加到我的项目中。现在我的项目没有编译,因为我在XAML中的
xmlns
查找失败。gzip背后的原因是什么?我以前见过,只是为了让主exe更小。GZip可以很好地压缩,大约50%左右。