24

我正在尝试使用 WebDeploy 使用自定义 MSDeploy 跳过规则和保存在 Visual Studio 2012 中的发布配置文件来发布网站。

我有从命令行运行的发布配置文件,但是跳过删除文件夹的跳过规则不起作用。

ErrorLog我的网络应用程序中有一个子文件夹,其中有一个web.config文件来设置正确的文件夹权限。没有任何跳过规则,ErrorLog文件夹和web.config文件正常发布,但服务器上文件夹中所有现有的错误日志文件在发布时被删除。


错误<SkipAction>Delete</SkipAction>

当我将自定义跳过规则添加到我的wpp.targets文件时,跳过规则不再接受<SkipAction>元素的值。如果我设置<SkipAction>Delete</SkipAction>,我会收到以下错误:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(4377,5): error : Web deployment task failed. (Unrecognized skip directive 'skipaction'. Must be one of the following: "objectName," "keyAttribute," "absolutePath," "xPath," "attributes.<name>.") [C:\inetpub\wwwroot\My.Website\My.Website\My.Website.csproj]

如果我只是省略了该<SkipAction>元素,则该ErrorLog文件夹会在正常发布时被删除。

如果我<SkipAction></SkipAction>再次设置,该ErrorLog文件夹会在发布时被删除。

如果我设置了<KeyAttribute>Delete</KeyAttribute>,那么ErrorLog文件web.config就会正常发布。

我的理解是,为了使用自定义跳过规则,您需要从命令行调用 MSBuild,而不是从 VS 2012 中发布。但是,我仍然想使用我保存的发布配置文件,我知道现在可以VS 2012 年。


我的 MSBuild 命令行:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe My.Website.sln /p:Configuration=Release;DeployOnBuild=true;PublishProfile="Test Server - Web Deploy"

My.Website.wpp.targets:

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

  <Target Name="AddCustomSkipRules">
    <Message Text="Adding Custom Skip Rules" />
    <ItemGroup>
      <MsDeploySkipRules Include="SkipErrorLogFolder1">
        <SkipAction></SkipAction>
        <KeyAttribute>Delete</KeyAttribute>
        <ObjectName>dirPath</ObjectName>
        <AbsolutePath>$(_Escaped_WPPAllFilesInSingleFolder)\\ErrorLog$</AbsolutePath>
        <XPath></XPath>
      </MsDeploySkipRules>
    </ItemGroup>
  </Target>
</Project>

我的 MSBuild 输出显示自定义跳过规则,但仍删除文件:

GenerateMsdeployManifestFiles:
  Generate source manifest file for Web Deploy package/publish ...
AddCustomSkipRules:
  Adding Custom Skip Rules
MSDeployPublish:
  Start Web Deploy Publish the Application/package to http://testserver.domain.com/MSDEPLOYAGENTSERVICE ...
  Starting Web deployment task from source: manifest(C:\inetpub\wwwroot\My.Website\My.Website\obj\Release\Package\My.Website.SourceManifest.xml) to Destination: auto().
  Deleting filePath (MyWeb/ErrorLog\test.txt).
  Updating setAcl (MyWeb/).
  Updating setAcl (MyWeb/).
  Updating filePath (MyWeb/ErrorLog\Web.config).
  Updating filePath (MyWeb/Web.config).
  Updating setAcl (MyWeb/).
  Updating setAcl (MyWeb/).
  Successfully executed Web deployment task.
  Publish is successfully deployed.
4

7 回答 7

23

编辑:事实证明你是对的:从 Visual Studio 执行时忽略跳过指令。

幸运的是,有一种解决方法。

你想要的是这样的:

<!-- Skip the deletion of any file within the ErrorLog directory -->
<MsDeploySkipRules Include="SkipErrorLogFolder1">
  <SkipAction>Delete</SkipAction>
  <ObjectName>filePath</ObjectName>
  <AbsolutePath>ErrorLog</AbsolutePath>
</MsDeploySkipRules>

此外,您需要阻止 VS 使用 UI 任务(这似乎包含有关跳过规则的错误)。您可以通过在 wpp.targets 或 pubxml 中声明以下内容来做到这一点:

<PropertyGroup>
  <UseMsDeployExe>true</UseMsDeployExe>
</PropertyGroup>

我已经在本地对此进行了测试,并且可以确认它可以按预期工作:附加文件已更新,但目录中没有文件被删除。

于 2012-09-25T06:12:44.420 回答
9

作为参考,这是我的完整.wpp.targets文件,其中包含工作跳过规则以跳过删除ErrorLog文件夹和自定义 ACL 以使ErrorLog文件夹在服务器上可写。

从 VS 2012 更新 3 开始,这仅适用于从命令行使用 MSBuild 发布,并将DeployOnBuild=true;PublishProfile="Test Server - Web Deploy"选项传递给 MSBuild。从 VS 中发布时,这将不起作用。

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <UseMsdeployExe>true</UseMsdeployExe> <!-- Required for the MSDeploySkipRules to work -->
    <DeployManagedPipelineMode>Integrated</DeployManagedPipelineMode>
  </PropertyGroup>

  <PropertyGroup>
    <AfterAddIisSettingAndFileContentsToSourceManifest>
      $(AfterAddIisSettingAndFileContentsToSourceManifest);
      AddCustomSkipRules;
    </AfterAddIisSettingAndFileContentsToSourceManifest>
  </PropertyGroup>

  <Target Name="AddCustomSkipRules">
    <Message Text="Adding Custom Skip Rules" />
    <ItemGroup>
      <MsDeploySkipRules Include="SkipErrorLogFolder">
        <SkipAction>Delete</SkipAction>
        <ObjectName>filePath</ObjectName>
        <AbsolutePath>ErrorLog</AbsolutePath>
        <XPath></XPath>
      </MsDeploySkipRules>
    </ItemGroup>
  </Target>

  <PropertyGroup>
    <AfterAddIisSettingAndFileContentsToSourceManifest>
      $(AfterAddIisSettingAndFileContentsToSourceManifest);
      SetCustomACLs;
    </AfterAddIisSettingAndFileContentsToSourceManifest>
    <AfterAddDeclareParametersItemsForContentPath>
      $(AfterAddDeclareParametersItemsForContentPath);
      SetCustomAclParameters;
    </AfterAddDeclareParametersItemsForContentPath>
  </PropertyGroup>

  <Target Name="SetCustomACLs">
    <Message Text="Setting Custom ACLs" />
    <ItemGroup>
      <!--Make sure the application pool identity has write permission to the download folder--> 
      <MsDeploySourceManifest Include="setAcl"
        Condition="$(IncludeSetAclProviderOnDestination) And Exists('$(_MSDeployDirPath_FullPath)\ErrorLog')">
        <Path>$(_MSDeployDirPath_FullPath)\ErrorLog</Path>
        <setAclAccess>Write</setAclAccess>
        <setAclResourceType>Directory</setAclResourceType>
        <AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings>
      </MsDeploySourceManifest>
    </ItemGroup>
  </Target>

  <Target Name="SetCustomAclParameters">
    <Message Text="Setting Custom ACL Parameters" />
    <EscapeTextForRegularExpressions Text="$(_MSDeployDirPath_FullPath)">
      <Output TaskParameter="Result" PropertyName="_EscapeRegEx_MSDeployDirPath" />
    </EscapeTextForRegularExpressions>
    <ItemGroup>
      <MsDeployDeclareParameters Include="Add write permission to ErrorLog folder"
        Condition="$(IncludeSetAclProviderOnDestination) and Exists('$(_MSDeployDirPath_FullPath)\ErrorLog')">
        <Kind>ProviderPath</Kind>
        <Scope>setAcl</Scope>
        <Match>^$(_EscapeRegEx_MSDeployDirPath)\\ErrorLog$</Match>
        <Description>Add write permission to ErrorLog folder</Description>
        <DefaultValue>Default Web Site/ErrorLog</DefaultValue>
        <Value>$(DeployIisAppPath)/ErrorLog</Value>
        <Tags>Hidden</Tags>
        <Priority>$(VsSetAclPriority)</Priority>
        <ExcludeFromSetParameter>True</ExcludeFromSetParameter>
      </MsDeployDeclareParameters>
    </ItemGroup>
  </Target>
</Project>
于 2013-09-24T20:32:41.220 回答
4

另一种方法是避免使用SkipAction标签,我已经直接从 VS 2013 成功使用了这个设置:

<Target Name="AddCustomSkipRules"
        AfterTargets="AddIisSettingAndFileContentsToSourceManifest">
    <Message Text="Adding Custom Skip Rules" />
    <ItemGroup>
        <MsDeploySkipRules Include="SkipMedia">
            <objectName>dirPath</objectName>
            <absolutePath>media</absolutePath>
        </MsDeploySkipRules>
        <MsDeploySkipRules Include="SkipUpload">
            <objectName>dirPath</objectName>
            <absolutePath>upload</absolutePath>
        </MsDeploySkipRules>
    </ItemGroup>
</Target>

据我所知,唯一需要注意的是,它将忽略更新、删除和添加操作。

于 2016-02-26T13:15:11.500 回答
2

经过几个小时通过网络查看。我在站点根文件夹下将此文件创建为 {myprojectname}.wpp.targets。它在使用 Visual Studio 发布时有效。媒体文件夹被忽略。我正在使用 VS 2010。

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <UseMsdeployExe>true</UseMsdeployExe>
        <!-- Required for the MSDeploySkipRules to work -->
        <DeployManagedPipelineMode>Integrated</DeployManagedPipelineMode>
    </PropertyGroup>

    <PropertyGroup>
        <AfterAddIisSettingAndFileContentsToSourceManifest>
            $(AfterAddIisSettingAndFileContentsToSourceManifest);
            AddCustomSkipRules;
        </AfterAddIisSettingAndFileContentsToSourceManifest>
    </PropertyGroup>

    <Target Name="AddCustomSkipRules">
        <Message Text="Adding Custom Skip Rules - WPP Targets 2" />
        <ItemGroup>
            <MsDeploySkipRules Include="SkipErrorLogFolder">
                <SkipAction>Delete</SkipAction>
                <ObjectName>dirPath</ObjectName>
                <AbsolutePath>media</AbsolutePath>
                <XPath></XPath>
                <Apply>Destination</Apply>
            </MsDeploySkipRules>
        </ItemGroup>
    </Target>
</Project>
于 2014-08-25T14:01:09.510 回答
0

I think the problem is in incorrect AbsolutePath. It should be a regular expression to match file or folder. so it should be properly escaped. Below is the sample which worked for me (I wanted to skip removal of app_offline.htm to make delivery part of larger deployment)

<PropertyGroup>
    <PackageUsingManifestDependsOn>$(PackageUsingManifestDependsOn);AddCustomSkipRules</PackageUsingManifestDependsOn>
  </PropertyGroup>
  <Target Name="AddCustomSkipRules">
    <ItemGroup>
      <MsDeploySkipRules Include="SkipAppOfflineOnDeploy">
        <SkipAction></SkipAction>
        <ObjectName>filePath</ObjectName>
        <AbsolutePath>app_offline\.htm</AbsolutePath>
        <Apply>Destination</Apply>
        <XPath></XPath>
      </MsDeploySkipRules>
    </ItemGroup>
  </Target>
于 2013-11-21T16:14:02.497 回答
0

对我有用:我的 Web 解决方案的 App_Data/PublishProfiles 文件夹中的完整 prepprod.pubxml 文件。Web Deploy 不再从 VS 2015 的 webdeploy 上的 cachefiles 文件夹中删除文件。第一个 PropertyGroup 是使用 Visual Studio 中的 Web 发布 gui 自动生成的。我添加了第二个 PropertyGroup,以及之前评论中的 Target 部分。

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <LastUsedBuildConfiguration>Production</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>{masked}</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <MSDeployServiceURL>{masked}</MSDeployServiceURL>
    <DeployIisAppPath>{masked}</DeployIisAppPath>
    <RemoteSitePhysicalPath />
    <SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    <MSDeployUseChecksum>true</MSDeployUseChecksum>
    <EnableMSDeployBackup>True</EnableMSDeployBackup>
    <UserName>{masked}</UserName>
    <_SavePWD>True</_SavePWD>
    <PublishDatabaseSettings>
      <Objects xmlns="">
      </Objects>
    </PublishDatabaseSettings>
    <ExcludeFilesFromDeployment>packages.config;*.bat;*.sln;*.suo,*.p4ignore</ExcludeFilesFromDeployment>
    <ExcludeFoldersFromDeployment>packages;cachefiles;.ebextensions</ExcludeFoldersFromDeployment>
  </PropertyGroup>

  <PropertyGroup>
    <AfterAddIisSettingAndFileContentsToSourceManifest>
      $(AfterAddIisSettingAndFileContentsToSourceManifest);
      AddCustomSkipRules;
    </AfterAddIisSettingAndFileContentsToSourceManifest>
  </PropertyGroup>

  <Target Name="AddCustomSkipRules">
    <Message Text="Adding Custom Skip Rules" />
    <ItemGroup>
      <MsDeploySkipRules Include="SkipcachefilesFolder">
        <objectName>dirPath</objectName>
        <absolutePath>cachefiles</absolutePath>
      </MsDeploySkipRules>
    </ItemGroup>
  </Target>

</Project>
于 2017-08-23T17:32:01.250 回答
0

这在 vs 2015 中对我有用,网站项目类型:

<!--Added inside existing <ProjectGroup> tag-->
<AfterAddIisSettingAndFileContentsToSourceManifest>AddCustomSkipRules</AfterAddIisSettingAndFileContentsToSourceManifest>

<!--Added new ProjectGroup tag inside <Project></Project>-->
<PropertyGroup>
   <WebPublishMethod>MSDeploy</WebPublishMethod>
</PropertyGroup>

<!--Added inside existing <Project> tag at the bottom-->
<Target Name="AddCustomSkipRules">
<Message Text="Adding Custom Skip Rules" />
 <ItemGroup>
  <MsDeploySkipRules Include="SkipConfigFolder">
    <SkipAction></SkipAction>
    <!--<KeyAttribute>Delete</KeyAttribute>-->
    <ObjectName>dirPath</ObjectName>
    <AbsolutePath>App_Data\\Composite\\Logfiles</AbsolutePath>
    <XPath>
    </XPath>
  </MsDeploySkipRules>
 </ItemGroup>
</Target>
于 2018-03-05T09:34:58.157 回答