当我发布一个web应用程序AfterPublish脚本不运行 [英] AfterPublish script doesn't run when I publish a web app

查看:204
本文介绍了当我发布一个web应用程序AfterPublish脚本不运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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文件正上方结束< /项目> 标签:

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

<Target Name="AfterPublish" >
    <Exec Command="C:\deg\bat\backupRMA.cmd" />
</Target>

这是继 MSDN中的说明覆盖目标

我也试图在 这太问题 。这是这样的:

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

<Target Name="BackUpRMAToIDrive" AfterTargets="MSDeployPublish" >
    <Exec Command="C:\deg\bat\backupRMA.cmd" />
</Target>

这也不行。

有关完整性,这里的批处理文件,它是pretty简单,但我可以解释一下开关,如果任何人的兴趣:

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

xcopy C:\deg\ASP.NET\OnlineRMA_SinglePage\*.* /cherkyDi I:\common\AppDevBranch\Service\rma

在我使用VS2010构建>发布RMA,工作正常发布。这只是备份脚本从未运行。唯一的共同点是脚本本身。我已经看到了使用从源代码目录复制到目标目录其他的例子,但我想我明白,你可以只通过exec命令调用外部脚本? <一href=\"http://stackoverflow.com/questions/15090558/post-build-event-command-for-publish-visual-studio-2010\">Here's这个例子SO问题,我发现这个方法

我敢肯定,我失去了一些东西很明显,但我到我的东西乱搞的第二天,似乎pretty直线前进,所以我错过了什么?

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?

推荐答案

当你手动运行CMD文件,脚本无疑具有管理员权限或足够的权限成功地将文件复制到目标上运行(在我:在这种情况下单元)

When you run the cmd file manually, the script surely runs with administrator privileges, or enough privileges to succesfully copy the files to the destination (in the I: unit in this case).

这是从Visual Studio执行该脚本可能已经非常有限的权限,出于安全性考虑的主题。

The thread that executes the script from Visual Studio probably has very restricted privileges, due to security reasons.

您最好的选择,是运行的PowerShell脚本,通过下面的参数是:

Your best bet, is run the script from powershell, passing the following argument to it:

-ExecutionPolicy无限制

-ExecutionPolicy Unrestricted

您的 XML 会是这样的:

Your XML will look like this:

<Target Name="CustomPostPublishActions" AfterTargets="MSDeployPublish">
  <PropertyGroup>
    <PowerShellExe Condition=" '$(PowerShellExe)'=='' "> 
      %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
    </PowerShellExe>
    <ScriptLocation Condition=" '$(ScriptLocation)'=='' ">
      C:\deg\bat\backupRMA.cmd
    </ScriptLocation>
  </PropertyGroup>
  <Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted 
                 -command &quot;&amp; invoke-command -scriptblock { 
                          &amp;&apos;$(ScriptLocation)&apos; 
                          }
                          &quot;"/>  
</Target>

您还可以检查此MSDN链接类似的命令:

You can also check this MSDN link for similar commands:

<一个href=\"http://www.asp.net/web-forms/tutorials/deployment/advanced-enterprise-web-deployment/running-windows-powershell-scripts-from-msbuild-project-files\" rel=\"nofollow\">http://www.asp.net/web-forms/tutorials/deployment/advanced-enterprise-web-deployment/running-windows-powershell-scripts-from-msbuild-project-files

这篇关于当我发布一个web应用程序AfterPublish脚本不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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