Set write permission to folders during webdeploy

08 Apr 2017

Microsoft webdeploy helps developers by simplifying the deployment of ASP.Net websites. It can

  • Package the required files for the deployment
  • Package an entire website along with the database, permission settings, registry settings etc., for migration
  • Easily package and deploy the package to multiple servers/farms
  • identifies missing dependencies & synchronize just the changed data
  • can perform backup of existing code/application before deployment

By default, web deploy assigns readonly permission for the files and folders during deployment. but we can tailor this behaviour to set the 'WRITE' access for specific folders.

Before deployment, web deploy creates a ACL list of folder. So inorder to add our required permission, create following file in your project root

solutioname.wpp.targets

Replace 'solutionname' in above filename with your solution name and it will be automatically picked up by the webdeploy tool before deployment.

Following sample wpp targets file, instructs the webdeploy tool to set read,write permission to folder that matches path "/content$"

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Target Name="SetupCustomAcls" AfterTargets="AddIisSettingAndFileContentsToSourceManifest">   
    <ItemGroup>
      <MsDeploySourceManifest Include="setAcl">
        <Path>$(_MSDeployDirPath_FullPath)\Content</Path>
        <setAclAccess>Read,Write</setAclAccess>
        <setAclResourceType>Directory</setAclResourceType>
        <AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings>
      </MsDeploySourceManifest>
    </ItemGroup>
  </Target>

  <Target Name="DeclareCustomParameters" AfterTargets="AddIisAndContentDeclareParametersItems">
    <ItemGroup>
      <MsDeployDeclareParameters Include="ArticleGallerySetAclParam">
        <Kind>ProviderPath</Kind>
        <Scope>setAcl</Scope>
        <Match>^$(_EscapeRegEx_MSDeployDirPath)\\Content$</Match>
        <Description>Add write permission to content folder.</Description>
        <DefaultValue>{$(_MsDeployParameterNameForContentPath)}/Content</DefaultValue>
        <Value>$(_DestinationContentPath)/Content</Value>
        <Tags>Hidden</Tags>
        <Priority>$(VsSetAclPriority)</Priority>
        <ExcludeFromSetParameter>True</ExcludeFromSetParameter>
      </MsDeployDeclareParameters>
    </ItemGroup>
  </Target>
  
</Project>