用户登录
用户注册

分享至

当我发布 Web 应用程序时,AfterPublish 脚本不运行

  • 作者: -逶迤唯一
  • 来源: 51数据库
  • 2023-02-13

问题描述

我有一个 ASP.NET Web 应用程序,我在进行更改或修复错误时将其发布到我们的网站.我们想自动将项目文件的备份保存到我们的服务器(与 SVN 签入分开),所以我编写了一个批处理文件将整个项目从我的本地驱动器复制到服务器.单独运行时批处理文件可以正常工作,所以这不是问题.如果这是一个问题,批处理文件不在项目的路径中.

I've got an ASP.NET web app that I publish to our website when I make changes or fix bugs. We want to automatically save a backup of the project files to our server (separate from the SVN check in), so I wrote a batch file to copy the entire project from my local drive to the server. The batch file works properly when run stand alone, so that's not the problem. The batch file is not in the path of the project if that's a concern.

然后我将这些行添加到我的 .csproj 文件中,就在结束 </project> 标记的正上方:

Then I added these lines to my .csproj file right above the closing </project> tag:

<Target Name="AfterPublish" >
    <Exec Command="C:degatackupRMA.cmd" />
</Target>

这遵循 用于覆盖目标的 MSDN.

我也尝试过 这个 SO question.看起来像这样:

I have also tried the method outlined in this SO question. Which looked like this:

<Target Name="BackUpRMAToIDrive" AfterTargets="MSDeployPublish" >
    <Exec Command="C:degatackupRMA.cmd" />
</Target>

这也不行.

为了完整起见,这里是批处理文件,它非常简单,但如果有人感兴趣,我可以解释一下开关:

For completeness, here's the batch file, it's pretty simple, but I can explain the switches if anyone's interested:

xcopy C:degASP.NETOnlineRMA_SinglePage*.* /cherkyDi I:commonAppDevBranchServicema

我使用 Build > Publish RMA 在 VS2010 中发布,效果很好.只是备份脚本永远不会运行.唯一的共同点是脚本本身.我见过其他使用从源目录到目标目录的副本的示例,但我想我明白你可以通过 Exec 命令调用外部脚本?这是我为该方法找到的示例 SO 问题.

I publish in VS2010 using Build > Publish RMA, which works fine. It's just the backup script never runs. The only commonality is the script itself. I've seen other examples that use a copy from source dir to destination dir, but I thought I understood that you could just call an external script through the Exec command? Here's the example SO question I found for that method.

我确定我遗漏了一些明显的东西,但是我已经进入第二天的事情了,看起来很简单,所以我遗漏了什么?

I'm certain I'm missing something obvious, but I'm onto my second day of messing around with something that seems pretty straight forward, so what am I missing?

推荐答案

我看到一位 MS 开发人员的评论指出,发布到文件系统"不会调用 MSDeployPublish 目标.你可以在这里看到.

I saw a comment from a MS developer stating that publishing that goes to the 'File System' does not call MSDeployPublish target. You can see that here.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/60b196e9-28e1-4d9d-b464-d57e42353754/vs2012-afterpublish-for-web-application?forum=msbuild

http://sedodream.com/PermaLink,guid,b352f04a-2449-4cbb-8125-7acdef9552e1.aspx

在 *.targets 文件中四处挖掘,我可以在 AfterTargets 属性中放置一些目标,这些目标在发布复制到 临时 obj 输出文件夹后完成运行.我永远找不到在复制到发布配置文件中定义的实际文件夹后运行的文件.

Digging around in the *.targets files there were a few targets I could place in the AfterTargets attribute that accomplished running after the publish had copied to the temporary obj output folder. I could never find one that ran after copying to the actual folder defined in the publish profile.

这是我认为您需要的:

  <Target Name="BackUpRMAToIDrive" AfterTargets="CopyAllFilesToSingleFolderForPackage">
    <Exec Command="C:degatackupRMA.cmd" />
  </Target>

我不确定您要备份什么 - 原始来源或已发布的来源.在执行此操作时,如果您需要已发布文件"的路径,您可以通过 $(WebProjectOutputDir)$(WPPAllFilesInSingleFolder) 将参数传递给您的脚本.这类似于 c:{path to *.csproj}obj{build configuration}PackagePackageTmp.

I'm not sure what you are backing up though - the original source or the published source. At the time of this Exec, if you need the path to the 'published files', you can pass in a parameter to your script via $(WebProjectOutputDir)$(WPPAllFilesInSingleFolder). This would be something like c:{path to *.csproj}obj{build configuration}PackagePackageTmp.

软件
前端设计
程序设计
Java相关