在Visual Studio 2012中使用MSBuild PublishProfile时,MSDeploy跳过规则 [英] MSDeploy skip rules when using MSBuild PublishProfile with Visual Studio 2012

查看:256
本文介绍了在Visual Studio 2012中使用MSBuild PublishProfile时,MSDeploy跳过规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use WebDeploy to publish a website using custom MSDeploy skip rules and a publish profile saved in Visual Studio 2012.

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

I have the publish profile working from the command line, but the skip rule to skip deleting a folder isn't working.

我的Web应用程序中有一个ErrorLog子文件夹,其中包含web.config文件,用于设置适当的文件夹权限.没有任何跳过规则,ErrorLog文件夹和web.config文件将正常发布,但是服务器上该文件夹中的所有现有错误日志文件都会在发布时删除.

I have an ErrorLog subfolder in my web app with a web.config file inside it to set the proper folder permissions. Without any skip rules, the ErrorLog folder and web.config file are published normally, but all existing error log files in the folder on the server are deleted on publish.

<SkipAction>Delete</SkipAction>

Error with <SkipAction>Delete</SkipAction>

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

When I add a custom skip rule to my wpp.targets file, the skip rule is no longer accepting a value for the <SkipAction> element. If I set <SkipAction>Delete</SkipAction>, I get the following error:

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文件夹时将其删除.

If I simply omit the <SkipAction> element, the ErrorLog folder is deleted when it would normally be published.

如果我设置了<SkipAction></SkipAction>,则ErrorLog文件夹也会在发布时删除.

If I set <SkipAction></SkipAction>, again, the ErrorLog folder is deleted on publish.

如果我设置了<KeyAttribute>Delete</KeyAttribute>,则ErrorLogweb.config文件将正常发布.

If I set <KeyAttribute>Delete</KeyAttribute>, then ErrorLog and the web.config file are published normally.

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

My understanding is that in order to use custom skip rules, you need to call MSBuild from the command line instead of publishing from within VS 2012. I'd still like to use my saved publishing profiles, however, and I understand that's now possible as of 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"


我的网站.wpp.目标:

<?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执行时,skip指令将被忽略.

It turns out you are right: the skip directive is ignored when executed from Visual Studio.

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

Fortunately, there's a workaround.

您想要的是什么

<!-- 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中声明以下内容来做到这一点:

In addition, you need to prevent VS from using the UI-task (which appears to contain a bug regarding the skip rules). You can do this by declaring the following in your wpp.targets or pubxml:

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

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

I've tested this locally and I can confirm that it works as desired: the additional file is updated but no files in the directory are deleted.

这篇关于在Visual Studio 2012中使用MSBuild PublishProfile时,MSDeploy跳过规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆