Can Web Deploy's setAcl provider be used on a sub-directory?

后端 未结 2 1923
盖世英雄少女心
盖世英雄少女心 2020-11-29 06:33

I\'m trying to make a subdirectory in an MS Deploy package writable to the application pool user. Thanks to a helpful post about the setAcl provider by Kevin Leetham I was

相关标签:
2条回答
  • 2020-11-29 07:16

    FYI - this does work for a root website if you follow the convention specified in the post here: http://forums.iis.net/p/1176955/1977169.aspx#1977169

    <Match>^$(_EscapeRegEx_MSDeployDirPath)\\@(CustomDirAcl)$</Match>
    <DefaultValue>{$(_MsDeployParameterNameForContentPath)}/@(CustomDirAcl)</DefaultValue>
    <Value>$(_DestinationContentPath)/@(CustomDirAcl)</Value>
    

    This post also has the benefit of being able to specify a block of subdirectories in a single ItemGroup.

    0 讨论(0)
  • 2020-11-29 07:29

    OK let me first say that this is way harder than it should be!

    I think the reason why it is failing is because when you are publishing it cannot recognize the folder as being a folder in the IIS Application. The reason this is happening is because the full path is being transferred to the destination when the SetAcl provider is invoked. Instead of that we need an path which is relative to the IIS Application. For instance in your case it should be something like : "REST SERVICES/1.0.334/doc/public". The only way to do this is to create an MSDeploy parameter which gets populated with the correct value at publish time. You will have to do this in addition to creating your own SetAcl entry in the source manifest. Follow the steps below.

    1. In the same directory as your project create a file with the name {ProjectName}.wpp.targets (where {ProjectName} is the name of your Web application project)
    2. Inside the file paste the MSBuild content which is below this list
    3. Reload the project in Visual Studio (VS caches the project files in memory so this cache needs to be cleared).

    {ProjectName}.wpp.targets

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    
      <Target Name="SetupCustomAcls" AfterTargets="AddIisSettingAndFileContentsToSourceManifest">   
        <!-- This must be declared inside of a target because the property 
        $(_MSDeployDirPath_FullPath) will not be defined at that time. -->
        <ItemGroup>
          <MsDeploySourceManifest Include="setAcl">
            <Path>$(_MSDeployDirPath_FullPath)\doc\public</Path>
            <setAclAccess>Read,Write,Modify</setAclAccess>
            <setAclResourceType>Directory</setAclResourceType>
            <AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings>
          </MsDeploySourceManifest>
        </ItemGroup>
      </Target>
    
      <Target Name="DeclareCustomParameters" AfterTargets="AddIisAndContentDeclareParametersItems">
        <!-- This must be declared inside of a target because the property 
        $(_EscapeRegEx_MSDeployDirPath) will not be defined at that time. -->
        <ItemGroup>
          <MsDeployDeclareParameters Include="DocPublicSetAclParam">
            <Kind>ProviderPath</Kind>
            <Scope>setAcl</Scope>
            <Match>^$(_EscapeRegEx_MSDeployDirPath)\\doc\\public$</Match>
            <Value>$(_DestinationContentPath)/doc/public</Value>
            <ExcludeFromSetParameter>True</ExcludeFromSetParameter>
          </MsDeployDeclareParameters>
        </ItemGroup>
      </Target>
    
    </Project>
    

    To explain this a bit, the target SetupCustomAcls will cause a new SetAcl entry to be placed inside of the source manifest used during publishing. This target is executed after the AddIisSettingAndFileContentsToSourceManifest target executes, via the AfterTargets attribute. We do this to ensure that the item value is created at the right time and because we need to ensure that the property _MSDeployDirPath_FullPath is populated.

    The DeclareCustomParameters is where the custom MSDeploy parameter will be created. That target will execute after the AddIisAndContentDeclareParametersItems target. We do this to ensure that the property _EscapeRegEx_MSDeployDirPath is populated. Notice inside that target when I declare the value of the parameter (inside the Value element) that I use the property _DestinationContentPath which is the MSBuild property containing the path to where your app is being deployed, i.e. REST Services/1.0.334.

    Can you try that out and let me know if it worked for you or not?

    0 讨论(0)
提交回复
热议问题