【问题标题】:MSDeploy skip rules when using MSBuild PublishProfile with Visual Studio 2012将 MSBuild PublishProfile 与 Visual Studio 2012 一起使用时的 MSDeploy 跳过规则
【发布时间】:2012-09-16 14:23:04
【问题描述】:

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

我的发布配置文件在命令行中工作,但跳过删除文件夹的跳过规则不起作用。

我的 Web 应用程序中有一个 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]

如果我只是省略&lt;SkipAction&gt; 元素,ErrorLog 文件夹会在正常发布时被删除。

如果我再次设置&lt;SkipAction&gt;&lt;/SkipAction&gt;ErrorLog 文件夹会在发布时被删除。

如果我设置&lt;KeyAttribute&gt;Delete&lt;/KeyAttribute&gt;,则ErrorLogweb.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.

【问题讨论】:

    标签: visual-studio msbuild visual-studio-2012 msdeploy webdeploy


    【解决方案1】:

    编辑: 事实证明你是对的:从 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>
    

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

    【讨论】:

    • 如果我使用您显示的跳过规则,没有SkipAction 值且没有KeyAttribute 元素,它确实会跳过删除ErrorLog 文件夹中的文件---这很好--- - 但它也会跳过发布 ErrorLog\web.config 文件 --- 不好。为什么我不能使用&lt;SkipAction&gt;Delete&lt;/SkipAction&gt;,就像网络上的所有示例(包括您的 Technet 链接)一样?顺便说一句,我的印象是跳过规则只有在使用 MSBuild.exe 构建时才起作用(A)之前在 VS 2010 中进行的测试,以及(B)this blog post
    • 指定一个 SkipAction 很好。
    • 不,不是 - 如果你指定&lt;SkipAction&gt;Delete&lt;/SkipAction&gt;,你会在我的开场问题中得到错误。如果您使用空元素指定&lt;SkipAction&gt;&lt;/SkipAction&gt;,则ErrorLog\web.config 不会发布
    • @nekno - 我不确定这个错误,但我发现了忽略跳过规则的解决方法。请参阅我的更新答案。
    • 谢谢,效果很好——我尝试了UseMsDeployExe 与不同SkipActionObjectNameAbsolutePath 值的各种组合,但我无法登陆在您发布的确切组合上。尽管尝试在 Microsoft 自己的 .targets 文件中使用正则表达式来模仿其他规则,但它似乎不适用于 AbsolutePath 值中的任何正则表达式。只有“ErrorLog”似乎确实有效。无论如何,它适用于我的场景。
    【解决方案2】:

    作为参考,这是我完整的 .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>
    

    【讨论】:

    • 整个目标文件非常宝贵。谢谢!
    【解决方案3】:

    我认为问题出在不正确的 AbsolutePath 上。它应该是匹配文件或文件夹的正则表达式。所以它应该被正确地转义。下面是对我有用的示例(我想跳过删除 app_offline.htm 以使交付成为更大部署的一部分)

    <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>
    

    【讨论】:

    • 不,你会从我的问题中看到我在AbsolutePath:$(_Escaped_WPPAllFilesInSingleFolder)\\ErrorLog$ 中使用了转义的正则表达式路径,所以这不是问题。你有一个不同的Apply 值,这可能是关键,不回去测试我不知道。
    【解决方案4】:

    经过数小时浏览网络。我在站点根文件夹下将此文件创建为 {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>
    

    【讨论】:

      【解决方案5】:

      另一种方法是避免使用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>
      

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

      【讨论】:

      • 这将跳过任何路径,包括“上传”和“媒体”关键字,而不仅仅是上传/媒体文件夹。
      【解决方案6】:

      为我工作:我的 Web 解决方案的 App_Data/PublishProfiles 文件夹中的完整 prepprod.pubxml 文件。 Web Deploy 不再从 VS 2015 的 webdeploy 上的 cachefiles 文件夹中删除文件。第一个 PropertyGroup 是使用 Visual Studio 中的 Web 发布 gui 自动生成的。我添加了第二个 PropertyGroup,以及之前 cmets 中的 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>
      

      【讨论】:

        【解决方案7】:

        这在 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>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-02-15
          • 2014-02-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-11-24
          • 2021-03-30
          • 2012-11-05
          相关资源
          最近更新 更多