Zip Task for MSBuild Community Tasks Changes File Attribute

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

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

      

Down below, I included these DLLs in the FilesToZip element and named the following:

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

      

After checking the extracted files, I found that none of the DLLs are read-only (much less any). Looking at the DLL folder where the Zip task grabbed the files showed that the DLLs have the R (read-only) attribute.

After reading both the documentation and the source code, I could not find any properties that I could set the job to preserve file attributes. Is there a replacement I can use to keep the file attributes intact? I tried looking into ICSharpCode.SharpZipLib as the Zip class in the community issue source references it, but so far I couldn't do much.

(I am using Community Tasks version 1.2.0.306)

+2


source to share


1 answer


Ok, now I'm going to answer my own question here, hoping it will be helpful to someone:

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

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

      



This is nothing like generic and reliable code that I should be using, but I wrote this to make sure this is the correct way to preserve file attributes, and it does seem to be the case.

PS If anyone has any suggestions on what could be improved here, PLEASE share your thoughts! As a developer, I am always open to learning :)

+1


source







All Articles