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

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

问题描述

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

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

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

删除

时出错

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

C:Program Files (x86)MSBuildMicrosoftVisualStudiov11.0WebMicrosoft.Web.Publishing.targets(4377,5):错误:Web 部署任务失败.(无法识别的跳过指令skipaction".必须是以下之一:objectName"、keyAttribute"、absolutePath"、xPath"、attributes..")[C:inetpubwwwrootMy.WebsiteMy.WebsiteMy.Website.csproj]

如果我简单地省略 元素,ErrorLog 文件夹会在正常发布时被删除.

如果我设置 ,同样,ErrorLog 文件夹在发布时被删除.

如果我设置了Delete,那么ErrorLogweb.config文件就正常发布了.

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

<小时>

我的 MSBuild 命令行:

C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe My.Website.sln/p:Configuration=Release;DeployOnBuild=true;PublishProfile="Test Server - Web Deploy"

<小时>

My.Website.wpp.targets:

<小时>

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

GenerateMsdeployManifestFiles:为 Web 部署包/发布生成源清单文件...添加自定义跳过规则:添加自定义跳过规则MSDeploy发布:启动 Web 部署 将应用程序/包发布到 http://testserver.domain.com/MSDEPLOYAGENTSERVICE ...从源启动 Web 部署任务:manifest(C:inetpubwwwrootMy.WebsiteMy.WebsiteobjReleasePackageMy.Website.SourceManifest.xml) 到目标:auto().正在删除文件路径 (MyWeb/ErrorLog	est.txt).更新 setAcl (MyWeb/).更新 setAcl (MyWeb/).更新文件路径 (MyWeb/ErrorLogWeb.config).更新文件路径 (MyWeb/Web.config).更新 setAcl (MyWeb/).更新 setAcl (MyWeb/).已成功执行 Web 部署任务.发布成功部署.

解决方案

事实证明您是对的:从 Visual Studio 执行时会忽略跳过指令.

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

你想要的是这个:

<!-- 跳过删除ErrorLog目录中的任何文件--><MsDeploySkipRules Include="SkipErrorLogFolder1"><SkipAction>删除</SkipAction><对象名称>文件路径</对象名称><AbsolutePath>ErrorLog</AbsolutePath></MsDeploySkipRules>

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

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

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

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.

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.


Error with <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)MSBuildMicrosoftVisualStudiov11.0WebMicrosoft.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:inetpubwwwrootMy.WebsiteMy.WebsiteMy.Website.csproj]

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

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

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

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.


My MSBuild command line:

C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.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>


My MSBuild output showing the custom skip rule, but still deleting the files:

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:inetpubwwwrootMy.WebsiteMy.WebsiteobjReleasePackageMy.Website.SourceManifest.xml) to Destination: auto().
  Deleting filePath (MyWeb/ErrorLog	est.txt).
  Updating setAcl (MyWeb/).
  Updating setAcl (MyWeb/).
  Updating filePath (MyWeb/ErrorLogWeb.config).
  Updating filePath (MyWeb/Web.config).
  Updating setAcl (MyWeb/).
  Updating setAcl (MyWeb/).
  Successfully executed Web deployment task.
  Publish is successfully deployed.

解决方案

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

Fortunately, there's a workaround.

What you want is this:

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

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天全站免登陆