今天繼續在研究Silverlight的釋出優化方法,由于項目需要開啟OOB,沒有辦法再選中
<a target="_blank" href="http://blog.51cto.com/attachment/201106/222549931.png"></a>
這兩個選項隻能選擇其中一個,很遺憾不能利用自身的功能合并項目了,這裡說明一下,第一個選項的好處
如果你的解決方案中有兩個Silverlight項目,那麼如果選擇了第一項,則兩個項目中共同的DLL會被壓縮放在ClientBin目錄下,這樣做的好處是避免了兩個SL項目中引用重複的DLL,但是選擇OOB之後,我們便不能選擇這個項了,于是我想到在OOB的基礎上,将打包好的XAP改成壓縮檔案,再解壓,将兩個項目中的公共DLL抽取出來放到ClientBin下,當然這樣做還涉及到Xap包中的一個檔案
代碼
<Deployment xmlns="<a href="http://schemas.microsoft.com/client/2007/deployment"">http://schemas.microsoft.com/client/2007/deployment"</a>
xmlns:x="<a href="http://schemas.microsoft.com/winfx/2006/xaml"">http://schemas.microsoft.com/winfx/2006/xaml"</a> EntryPointAssembly="ProjectA"
EntryPointType="ProjectA.App" RuntimeVersion="4.0.50401.0">
<Deployment.OutOfBrowserSettings>
<OutOfBrowserSettings ShortName="ProjectA Application" EnableGPUAcceleration="False"
ShowInstallMenuItem="True">
<OutOfBrowserSettings.Blurb>ProjectA Application on your desktop; at home, at work or on the
go.</OutOfBrowserSettings.Blurb>
<OutOfBrowserSettings.WindowSettings>
<WindowSettings Title="ProjectA Application" />
</OutOfBrowserSettings.WindowSettings>
<OutOfBrowserSettings.Icons />
</OutOfBrowserSettings>
</Deployment.OutOfBrowserSettings>
<Deployment.Parts>
<AssemblyPart x:Name="ProjectA" Source="ProjectA.dll" />
<AssemblyPart x:Name="ProjectB" Source="ProjectB.dll" />
<AssemblyPart x:Name="System.Windows.Controls" Source="System.Windows.Controls.dll" />
<AssemblyPart x:Name="Telerik.Windows.Controls" Source="Telerik.Windows.Controls.dll" />
</Deployment.Parts>
</Deployment>
我想将最後兩個DLL抽取出來或者改變一下配置路徑,但兩種方法都沒有用,有了解的朋友還請指點。
在解決問題的過程中我下載下傳了一個挺不錯的壓縮元件
SharpZipLib 有興趣的朋友可以試試
<a href="http://www.icsharpcode.net/OpenSource/SharpZipLib/">http://www.icsharpcode.net/OpenSource/SharpZipLib/</a>
簡單寫了一個類實作壓縮和解壓縮功能。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
namespace SLProjectsDownLoad.Web
{
public class Zip
{
public static void ZipFiles(string ZipFileName, string FromDirectory)
{
FastZip fz = new FastZip();
fz.CreateEmptyDirectories = true;
fz.CreateZip(ZipFileName, FromDirectory, true, "");
fz = null;
}
public static void UnZipFiles(string ZipFileName, string ToDirectory)
if (!Directory.Exists(ToDirectory))
Directory.CreateDirectory(ToDirectory);
ZipInputStream s = new ZipInputStream(File.OpenRead(ZipFileName));
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
if (directoryName != String.Empty)
Directory.CreateDirectory(ToDirectory + directoryName);
if (fileName != String.Empty)
{
FileStream streamWriter = File.Create(ToDirectory + theEntry.Name);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
break;
}
streamWriter.Close();
}
}
s.Close();
}
}
}
本文轉自wengyuli 51CTO部落格,原文連結:http://blog.51cto.com/wengyuli/586793,如需轉載請自行聯系原作者