Dec 29, 2008 at 1:55 PM
Edited Dec 29, 2008 at 6:58 PM
"There is no compression level setting in this library. You can choose compression or no compression."
Yea I that's what I came across... I zip the files with #ziplib, windows or winrar and the file is 11mb compressed. When i use dotnetzip its 13mb.
"I skimmed the article you mentioned but I don't really know what you mean by pointing me to it - it is an article that describes #ziplib, which is not this library.
There is an example of how to use DotNetZip in an ASP.NET page - available at http://www.codeplex.com/DotNetZip/Wiki/View.aspx?title=ASPNET%20Example%201&referringTitle=Examples
Yes, I looked at all the examples, I'm using this code in msbuild.community.tasks (http://msbuildtasks.tigris.org/). I was trying to update it to use dotnetzip instead of sharpziplib (its using the code I linked
you too).. Here is my code.
private static string CleanName( string name )
if ( name == null )
if ( Path.IsPathRooted( name ) )
// NOTE: for UNC names...
\\machine\share\zoom\beet.txt gives \zoom\beet.txt
name = name.Substring( Path.GetPathRoot( name ).Length );
name = name.Replace( @"\", "/" );
while ( ( name.Length > 0 ) && ( name[ 0 ] == '/' ) )
name = name.Remove( 0, 1 );
private bool ZipFiles()
Log.LogMessage( MSBuild.Community.Tasks.Properties.Resources.ZipCreating, _zipFileName );
using ( ZipFile zip = new ZipFile( File.Create( _zipFileName ) ) )
// add files to zip
foreach ( ITaskItem fileItem in _files )
string name = fileItem.ItemSpec;
FileInfo file = new FileInfo( name );
if ( !file.Exists )
// maybe a directory
DirectoryInfo directory = new DirectoryInfo( name );
if ( directory.Exists )
if ( !_flatten )
bool directoryStartsWith = name.StartsWith(
_workingDirectory, true, CultureInfo.InvariantCulture );
if ( !string.IsNullOrEmpty( _workingDirectory
) && directoryStartsWith )
name = name.Remove(
0, _workingDirectory.Length );
if ( !string.IsNullOrEmpty( name ) )
name = CleanName( name
+ Path.DirectorySeparatorChar );
// clean up name
if ( _flatten )
name = file.Name;
else if ( !string.IsNullOrEmpty( _workingDirectory )
&& name.StartsWith( _workingDirectory, true, CultureInfo.InvariantCulture
name = name.Remove( 0, _workingDirectory.Length );
Log.LogMessage( MSBuild.Community.Tasks.Properties.Resources.ZipAdded, name );
} // foreach file
Log.LogMessage( MSBuild.Community.Tasks.Properties.Resources.ZipSuccessfully, _zipFileName );
catch ( Exception exc )
Log.LogErrorFromException( exc );
"I don't know what you mean by "I have a task that needs to be executed right after the save and implementing an event" - Not sure what that has to do with creating a zip file. "
The problem is that MSBuild is using the zip task to zip x number of files. Immediately after the zip task returns the next msbuild task is run which try's copying the zip file. But the zip file is still in use (saving).
Also I don't know what you mean by "save can only be called once."
When I put the save() inside of the foreach, the file size grew to around 400mb and it had only added the first entry added to the zip. It has to do with how the save method was implemented.
What I really need is to have the zip file automatitaclly add the new files to the archive. So when the next msbuild task runs the zip file will be up-to-date and not saving a 14mb zip..