I'm creating a zip file from msbuild using the package target. It creates开发者_运维技巧 it fine and the folder I'm putting it in has permissions for a user that allows that user to have full control of the folder. However, when I remove the zip file, then run msbuild to create the zip file again the zip file has lost the permissions for that user.
So then I am using a certain user to programatically deploy the package file and that user no longer has permissions.
How can I force that zip file to inherit the permissions from the parent folder so I don't have to manually add the permissions back to the zip file each time msbuild creates it?
It would be better to restore permission inheritance for zip file, like this
icacls {packageFileName.zip} /reset
Turns out there isn't a specific way to tell the Package target to set the permissions. So the workaround is to set the permissions yourself after the Package target.
Here is how I did it. The regular expression part is to pull the name of the project file out of the project file path we have in our build script. That name matches up to the .\Output\Packages\ folder that is created. I then call cacls inside an exec command to set the permissions on every file in that directory for the user I specify.
<Target Name="Package">
<MSBuild Projects="@(PackageProject)" Targets="Package" Properties="Platform=$(Platform);
Configuration=$(Configuration);
DeployOnBuild=true;
DeployTarget=Package;
PackageLocation=$(PackageOutputDir)\$([System.Text.RegularExpressions.Regex]::Split($(ProjectName), '(.*\\)([a-z,A-Z,0-9,_,-]+)(\.\*proj;)')[2])\$([System.Text.RegularExpressions.Regex]::Split($(ProjectName), '(.*\\)([a-z,A-Z,0-9,_,-]+)(\.\*proj;)')[2]).zip;
PackageAsSingleFile=true;
ExcludeFilesFromDeployment=Web.config;
_PackageTempDir=$(PackageOutputDir)\temp;">
</MSBuild>
<Exec Command="echo y| cacls $(PackageOutputDir)\$([System.Text.RegularExpressions.Regex]::Split($(ProjectName), '(.*\\)([a-z,A-Z,0-9,_,-]+)(\.\*proj;)')[2])\* /G NetworkService:F"/>
</Target>
精彩评论