将 MSBuild PublishProfile 与 Visual Studio 2012 一起使用时,MSDeploy 跳过规则 [英] MSDeploy skip rules when using MSBuild PublishProfile with Visual Studio 2012

查看:22
本文介绍了将 MSBuild PublishProfile 与 Visual Studio 2012 一起使用时,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>

当我向 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)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]

如果我只是省略 <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: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>

<小时>

我的 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: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.

推荐答案

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

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

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