DD4T: Setting write permissions using MSDeploy

DD4T, Tridion, Continuous Integration, MSDeploy

When using DD4T or using dynamic publishing with a .NET application you might want to have a writable directory to store your binaries. When using Web Deploy, you can choose to do this when you publish.

  1. Create a file called [ProjectName].wpp.Targets where [ProjectName] is the same name as your .csproj file of your Web project.
  2. Copy/Paste the code below:
<?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)\BinaryData</Path>
                <setAclAccess>Read,Write,Modify</setAclAccess>
                <setAclResourceType>Directory</setAclResourceType>
                <AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings>
            </MsDeploySourceManifest>
        </ItemGroup>
    </Target>

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

</Project>

This script will automatically create the BinaryData folder for you, set write permissions on it and add it to the msbuild manifest. So no need anymore to add it manually and no server configuration anymore.

Source code updated on GitHub: DD4T.Package.Sample