在Visual Studio 2012中使用MSBuild PublishProfile时,MSDeploy跳过规则

问题描述 投票:23回答:7

我正在尝试使用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>,那么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
7个回答
22
投票

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

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

你想要的是这个:

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

我在本地测试了这个,我可以确认它是否按预期工作:附加文件已更新,但目录中没有文件被删除。


9
投票

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

从VS 2012 Update 3开始,这仅适用于从命令行使用MSBuild发布并且传递给MSBuild的DeployOnBuild=true;PublishProfile="Test Server - Web Deploy"选项。从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
投票

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

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


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>

0
投票

我认为问题在于不正确的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>

0
投票

适用于我:我的Web解决方案中的App_Data / PublishProfiles文件夹中的My prepprod.pubxml文件。 Web部署不再从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>

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>
© www.soinside.com 2019 - 2024. All rights reserved.