我有 silverlight XAP 的字节数组。我需要从字节数组中提取 xap 内的所有 dll。获得 dll 后,我需要从中提取程序集。Silverlight XAP 存储在存储库中,存储库总是返回 XAP 字节数组。C# 中是否有可用的标准 API 来实现此功能?如果没有,我们如何实现这个?
问候,阿布舍克
最佳答案
从字节数组创建一个 MemoryStream 并调用此函数:
public List<Assembly> ExtractAssembliesFromXap(Stream stream) {
List<Assembly> assemblies = new List<Assembly>();
string appManifest = new StreamReader(Application.GetResourceStream(
new StreamResourceInfo(stream, null), new Uri("AppManifest.xaml",
UriKind.Relative)).Stream).ReadToEnd();
XElement deploy = XDocument.Parse(appManifest).Root;
List<XElement> parts = (from assemblyParts in deploy.Elements().Elements()
select assemblyParts).ToList();
foreach (XElement xe in parts) {
string source = xe.Attribute("Source").Value;
AssemblyPart asmPart = new AssemblyPart();
StreamResourceInfo streamInfo = Application.GetResourceStream(
new StreamResourceInfo(stream, "application/binary"),
new Uri(source, UriKind.Relative));
assemblies.Add(asmPart.Load(streamInfo.Stream));
}
return assemblies;
}
关于silverlight-4.0 - 从 xap 内部的所有 dll 中提取程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3801065/