Iis 7 通过MSBuild在Web部署期间设置ACL

Iis 7 通过MSBuild在Web部署期间设置ACL,iis-7,msbuild,msdeploy,msbuild-wpp,Iis 7,Msbuild,Msdeploy,Msbuild Wpp,我在TeamCity中运行了一个主要工作的web构建和部署配置,它基本上使用MSBuild将站点自动部署到web服务器。默认情况下,MSDeploy将目标服务器上的所有内容都设置为只读,我需要AppPool标识才能对一个文件夹具有写访问权限 我发现这让我有90%的机会去那里。Kevin描述了如何通过创建名为ProjectName.wpp.targets的文件来连接到MSBuild Web发布管道,大致如下: <Project xmlns="http://schemas.microsoft.

我在TeamCity中运行了一个主要工作的web构建和部署配置,它基本上使用MSBuild将站点自动部署到web服务器。默认情况下,MSDeploy将目标服务器上的所有内容都设置为只读,我需要AppPool标识才能对一个文件夹具有写访问权限

我发现这让我有90%的机会去那里。Kevin描述了如何通过创建名为ProjectName.wpp.targets的文件来连接到MSBuild Web发布管道,大致如下:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
     <!--Extends the AfterAddIisSettingAndFileContentsToSourceManifest action do also set ACLs -->

    <IncludeCustomACLs>TRUE</IncludeCustomACLs>

    <AfterAddIisSettingAndFileContentsToSourceManifest Condition="'$(AfterAddIisSettingAndFileContentsToSourceManifest)'==''">
      $(AfterAddIisSettingAndFileContentsToSourceManifest);
      SetCustomACLs;
    </AfterAddIisSettingAndFileContentsToSourceManifest>
  </PropertyGroup>
  <Target Name="SetCustomACLs" Condition="'$(IncludeCustomACLs)'=='TRUE'">
    <Message Text="Adding Custom ACls" />
    <ItemGroup>
      <!-- Ensure the AppPool identity has write access to the Files directory -->
      <MsDeploySourceManifest Include="setAcl" Condition="$(IncludeSetAclProviderOnDestination)">
        <Path>$(_MSDeployDirPath_FullPath)\files</Path>
        <setAclAccess>Read,Write,Modify</setAclAccess>
        <setAclResourceType>Directory</setAclResourceType>
        <AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings>
      </MsDeploySourceManifest>
    </ItemGroup>
  </Target>
</Project>

真的
$(在将设置和文件内容添加到源清单之后);
SetCustomACLs;
$(\u MSDeployDirPath\u FullPath)\n文件
读、写、修改
目录
setAclResourceType;setAclAccess
这是如此接近工作,它是让我发疯。ACL被添加到清单中,但问题是它基于生成位置生成绝对路径,而不是相对于目标服务器上的IIS web应用。生成的清单如下所示(一些名称已更改以保护无辜者):


这实际上看起来是正确的,最后一行是wpp.targets文件中的自定义ACL。但是,当MSDeploy将其发送到目标服务器时,会发生以下情况:

2>Start Web Deploy Publish the Application/package to https://webhostingprovider.biz:8172/msdeploy.axd?site=IisWebAppName ... 2>Adding sitemanifest (sitemanifest). 2>Adding ACL's for path (IisWebAppName) 2>Adding ACL's for path (IisWebAppName) 2>Adding ACL's for path (C:\SolutionPath\IisWebAppname\src\MyProjectName\obj\Release_Deploy\Package\PackageTmp\files) 2>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(4377,5): Error ERROR_USER_NOT_AUTHORIZED_FOR_SETACL: Web deployment task failed. (Could not complete an operation with the specified provider ("setAcl") when connecting using the Web Management Service. This can occur if the server administrator has not authorized the user for this operation. setAcl http://go.microsoft.com/fwlink/?LinkId=178034 2> 启动Web部署将应用程序/包发布到https://webhostingprovider.biz:8172/msdeploy.axd?site=IisWebAppName ... 2> 正在添加sitemanifest(sitemanifest)。 2> 正在为路径(IISWebapName)添加ACL 2> 正在为路径(IISWebapName)添加ACL 2> 为路径(C:\SolutionPath\IISWebapName\src\MyProjectName\obj\Release\U Deploy\Package\PackageMP\files)添加ACL 2> C:\Program Files(x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(4377,5):错误\u用户\u未\u授权\u SETACL:Web部署任务失败。(使用Web管理服务连接时,无法使用指定的提供程序(“setAcl”)完成操作。如果服务器管理员未授权用户执行此操作,则可能会发生这种情况。setAclhttp://go.microsoft.com/fwlink/?LinkId=178034 整个事情都落在我的自定义ACL路径上,它使用绝对路径名,而不是相对于IISWebapName。我不明白为什么


请帮助:)

您需要创建一个带有
DefaultValue
ProviderPath
参数,该参数使用
{param name}
语法获取另一个参数的值

下面是我包含的一个助手,它执行所有操作:

<ItemDefinitionGroup>
  <AdditionalAcls>
    <AclAccess>Write</AclAccess>
    <ResourceType>Directory</ResourceType>
  </AdditionalAcls>
</ItemDefinitionGroup>

<PropertyGroup>
  <AfterAddIisSettingAndFileContentsToSourceManifest>
    $(AfterAddIisSettingAndFileContentsToSourceManifest);
    AddAdditionalAclsToSourceManifest;
  </AfterAddIisSettingAndFileContentsToSourceManifest>
  <AfterAddIisAndContentDeclareParametersItems>
    $(AfterAddIisAndContentDeclareParametersItems);
    AddAdditionalAclsDeclareParameterItems
  </AfterAddIisAndContentDeclareParametersItems>
</PropertyGroup>

<Target Name="AddAdditionalAclsToSourceManifest">
  <ItemGroup Condition="'@(AdditionalAcls)' != ''">
    <MsDeploySourceManifest Include="setAcl">
      <Path>$(_MSDeployDirPath_FullPath)\%(AdditionalAcls.Identity)</Path>
      <setAclResourceType Condition="'%(AdditionalAcls.ResourceType)' != ''">%(AdditionalAcls.ResourceType)</setAclResourceType>
      <setAclAccess>%(AdditionalAcls.AclAccess)</setAclAccess>
      <AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings>
    </MsDeploySourceManifest>
  </ItemGroup>
</Target>

<Target Name="AddAdditionalAclsDeclareParameterItems">
  <ItemGroup Condition="'@(AdditionalAcls)' != ''">
    <MsDeployDeclareParameters Include="Add %(AdditionalAcls.AclAccess) permission to %(AdditionalAcls.Identity) Folder">
      <Kind>ProviderPath</Kind>
      <Scope>setAcl</Scope>
      <Match>^$(_EscapeRegEx_MSDeployDirPath)\\@(AdditionalAcls)$</Match>
      <Description>Add %(AdditionalAcls.AclAccess) permission to %(AdditionalAcls.Identity) Folder</Description>
      <DefaultValue>{$(_MsDeployParameterNameForContentPath)}/@(AdditionalAcls)</DefaultValue>
      <DestinationContentPath>$(_DestinationContentPath)/@(AdditionalAcls)</DestinationContentPath>
      <Tags>Hidden</Tags>
      <ExcludeFromSetParameter>True</ExcludeFromSetParameter>
      <Priority>$(VsSetAclPriority)</Priority>
    </MsDeployDeclareParameters>
  </ItemGroup>
</Target>

写
目录
$(在将设置和文件内容添加到源清单之后);
AddAdditionalAclsToSourceManifest;
$(添加和内容声明参数后);
添加附加ACLSDclareParameterItems
$(\u MSDeployDirPath\u FullPath)\%(AdditionalAcls.Identity)
%(附加ACLS.ResourceType)
%(附加ACL.AclAccess)
setAclResourceType;setAclAccess
提供者路径
setAcl
^$(\u EscapeRegEx\u MSDeployDirPath)\\@(其他ACL)$
将%(AdditionalAcls.AclAccess)权限添加到%(AdditionalAcls.Identity)文件夹
{$(\u MsDeployParameterNameForContentPath)}/@(附加ACL)
$(_DestinationContentPath)/@(附加ACL)
隐藏的
真的
$(VsSetAclPriority)
您可以通过声明以下内容来使用它:

<ItemGroup>
    <AdditionalAcls Include="MyRelativeWritableDirectory" />
</ItemGroup>


请注意只有在路径中不需要反斜杠(即,如果它只是根目录)的情况下,此解决方案当前才有效。如果您需要一个子目录,您需要窃取我在“SkipDeleteItems”(后面的答案)中使用的技巧,将regex转义路径元数据添加到每个项。

这对我不起作用。我得到以下输出:2>启动Web部署将应用程序/包发布到。。。2> 正在添加sitemanifest(sitemanifest)。2> 为路径(IISWebapName)添加ACL 2>为路径(IISWebapName)添加ACL 2>为路径({IIS Web应用程序名称}/文件)[snip]2>发布未能部署。实际错误是什么?请尝试在pubxml中启用
UseMsDeployExe
,以查看它实际发送到
msdeploy.exe
的内容。错误是,文本字符串“{IIS Web应用程序名称}/files”被用作路径,而不是实际的Web应用程序名称。然后,tearget服务器拒绝该请求,因为它是一个无效路径。您能否尝试在pubxml中设置
true
,看看这是否可以修复错误?
<ItemGroup>
    <AdditionalAcls Include="MyRelativeWritableDirectory" />
</ItemGroup>