简体   繁体   中英

Running post deployment script after Web Deploy

I have the following problem and I'm surprised that I can't find any straightforward solution on SO or MSDN.

I have existing *.pubxml profiles in several of my web applications and I would like to execute post deployment script - powershell script - which reorganizes WebSite and its child applications slightly.

I'm not usign Web Deployment Package - just Web Deploy.

The script is deployed successfully but the problem is - how should I execute it automatically after deployment?

I have two scenarios:

  1. Execute by simply "Publish..." from Visual Studio.
  2. Execute as part of TFS Build definition (TFS 2013).

You should switch to deploying from Build & Release only in VSTS/TFS.

在此处输入图片说明

You can then add a PowerShell build task and either point at a script or use Inline if it's short. If it is a script that you use in many builds you might want to write your own build task.

You can try to define a “Target” by MSBuild to achieve your requirement.

For the first scenario:

The Visual Studio build process is defined by a series of MSBuild .targets files that are imported into your project file. One of these imported files, Microsoft.Common.targets. This file contains a set of predefined empty targets that are called before and after some of the major targets in the build process.

So you can define a "Target" element whose "AfterTarget" attribute's value is set to "MSDeployPublish":

<Target Name="CustomPostPublishActions" AfterTargets="MSDeployPublish" >
    <Exec Command="..\PostDeploymentScript.sp1 " />
</Target>

For the second scenario:

You can add a PowerShell build task as MrHinsh`s suggestion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM