Injecting deploy.ps1 script in AppVeyor build

We recently had some trouble with AppVeyor, running post-deployment actions after web projects are deployed on our Deployment Agent servers. A good example of this is that I wanted to go ahead and warm up an ASP.NET site after a Deployment Agent finishes deploying the web package. (Why should a user be the first one to wait for ASP.NET to spin up, right?)

AppVeyor has great pre-deployment and post-deployment script support built in. But "post-deployment" to AppVeyor means something completely different when using a Deployment Agent; it really means after the deployment agent job has been queued.

To actually run post-deployment actions on the server that did the deploying, a deploy.ps1 PowerShell script has to be in the root project folder of the deployed web package. See for that.

To get it into the web package, MSBuild has to build it into the web package. For MSBuild to do that, it has to be a part of your project. This means that you would have to add a deploy.ps1 file to your project root in your Visual Studio project. That's great, but it's a bad mix of deployment dependencies and application code. No bueno. And, sometimes you don't control the project, so this must be done during the build process - within AppVeyor.

So, here's my current solution (until AppVeyor supports this as a feature):

This PowerShell script, when run like so...

deploy-script-inject.ps1 -scriptUrl

... will do the following:

  1. Download the post-deployment script from the -scriptUrl address.
  2. Search for all *.csproj and *.vbproj files recursively in the current folder.
  3. Write post-deployment script as deploy.ps1 to the project's root folder.
  4. Modify the Visual Studio project XML to include the deploy.ps1 file.

After that, it will be carried through to the web deployment package, and AppVeyor's Deployment Agent will see it and run it post-deployment.

To put it all together, add the following lines to an AppVeyor "Before Build Script":

appveyor DownloadFile -FileName .\deploy-script-inject.ps1

powershell ".\deploy-script-inject.ps1 -scriptUrl YOUR_DEPLOY_SCRIPT_URL_HERE"

That's it - AppVeyor deployment script injection into Visual Studio projects at build time.

  • Akhil

    What is the value of YOUR_DEPLOY_SCRIPT_URL_HERE in the powershell script?

    • Brandon Potter

      You will need to host the powershell script you actually want to be run, and put its URL in that value.