不错的开源压缩组件(可惜没能用上)
今天继续在研究Silverlight的发布优化方法,由于项目需要开启OOB,没有办法再选中
这两个选项只能选择其中一个,很遗憾不能利用自身的功能合并项目了,这里说明一下,第一个选项的好处
如果你的解决方案中有两个Silverlight项目,那么如果选择了第一项,则两个项目中共同的DLL会被压缩放在ClientBin目录下,这样做的好处是避免了两个SL项目中引用重复的DLL,但是选择OOB之后,我们便不能选择这个项了,于是我想到在OOB的基础上,将打包好的XAP改成压缩文件,再解压,将两个项目中的公共DLL抽取出来放到ClientBin下,当然这样做还涉及到Xap包中的一个文件
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
<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>
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 有兴趣的朋友可以试试
http://www.icsharpcode.net/OpenSource/SharpZipLib/
简单写了一个类实现压缩和解压缩功能。
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
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();
}
}
}
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();
}
}
}