Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

c# - AfterPublish script doesn't run when I publish a web app

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.

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

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

This follows the instructions in MSDN for overriding a target.

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>

That doesn't work either.

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:commonAppDevBranchService
ma

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.

Here is what I think you would need:

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...