public static string CompileNewXAP(HashSet<string> fullsetOfDlls, string shared)
{
var tempPath = Path.Combine(shared, Guid.NewGuid() + ".xap");
using (
var stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("sl_runner.xap.sl-50-xap.xap"))
using (var baseZip = ZipFile.Read(stream))
{
var set = new HashSet<string>();
var item = baseZip["AppManifest.xaml"];
var xml = XDocument.Parse(new StreamReader(item.OpenReader()).ReadToEnd());
using (
var zip = new ZipFile()
{
CompressionLevel = CompressionLevel.Default,
CompressionMethod = CompressionMethod.Deflate
})
{
zip.AddEntry("AppManifest.xaml", new byte[] { });
foreach (var entry in baseZip.Entries)
{
if (entry.FileName.Contains(".dll"))
{
using (var memstream = new MemoryStream())
{
entry.OpenReader().CopyTo(memstream);
memstream.Seek(0, SeekOrigin.Begin);
zip.AddEntry(entry.FileName, memstream.ToArray());
set.Add(Path.GetFileName(entry.FileName));
}
}
}
var desc = xml.DescendantNodes().OfType<XElement>();
var parts = desc.Single(it => it.Name.LocalName.Contains("Deployment.Parts"));
foreach (var dll in fullsetOfDlls)
{
if (set.Contains(Path.GetFileName(dll)))
continue;
set.Add(Path.GetFileName(dll));
zip.AddFile(dll, "");
parts.Add(new XElement(XName.Get("AssemblyPart", "http://schemas.microsoft.com/client/2007/deployment"),
new XAttribute(
XName.Get("Name", "http://schemas.microsoft.com/winfx/2006/xaml"),
Path.GetFileNameWithoutExtension(dll)),
new XAttribute("Source", Path.GetFileName(dll))));
}
using (var memstream = new MemoryStream())
{
xml.Save(memstream, SaveOptions.OmitDuplicateNamespaces);
zip.UpdateEntry("AppManifest.xaml", memstream.ToArray());
}
zip.Save(tempPath);
}
}
return tempPath;
}