views:

890

answers:

1

I have found that creating a zip file using the Zip task provided by MSBuild Community Tasks changes (or rather, deletes) any file attributes of the files being zipped. Here is one of my calls to the Attrib task to make DLLs inside a folder have the read-only attribute:

<Attrib ReadOnly="true" Normal="true" Files="@(DLLsToReadOnly)" />

Down the road, I included these DLLs in a FilesToZip Item and called the following:

<Zip Files="@(FilesToZip)" WorkingDirectory="$(Directory with files)" ZipFileName="$(DropLocation)\$(Zip file name).zip" />

Upon inspection of the extracted files, I found that none of the DLLs had a read-only attribute (much less, any). Looking in the folder with the DLLs where the Zip task grabbed the files from showed that the DLLs had the attribute R (for Read-Only).

Having read both the documentation and the source code, I could not find any properties that I could set to tell the task to keep file attributes. Is there a substitute that I can use that would keep file attributes intact? I have tried looking into ICSharpCode.SharpZipLib as the Zip class in the Community Tasks source references it, but so far, I haven't been able to make much out of it.

(I am using Community Tasks version 1.2.0.306)

+1  A: 

OK, so now I'm going to answer my own question here in hopes that it will be useful to someone:

In the source code for the Zip task (MSBuild.Community.Tasks.Zip), the private method ZipFiles() does nothing to set or look at any external attributes (which are the file attributes of each file being zipped by the task). Since I only needed to keep attributes intact for files with Read-Only attributes, I wrote the following code to serve my simple purpose:

if ((file.Attributes & FileAttributes.ReadOnly)
{
     entry.ExternalFileAttributes = (int)FileAttributes.ReadOnly;
}

This is nothing near the generic and robust code I should be using, but I wrote this to see if this was the correct way to preserve file attributes, and that indeed seems to be case.

P.S. If anyone has suggestions on what can be improved here, PLEASE share your thoughts! As a fledgling developer, I'm always open for education :)

k4k4sh1