How to integrate common deploy.ps1 script in web deploys with deployment agent

Brandon's Avatar


23 Sep, 2015 03:54 PM

I've tried a few different variations / places for a deploy.ps1 script. Our typical deployment scenario is packaging up a ASP.NET web project and deploying it automatically through a deployment agent. I'd like to call a URL when that deployment is done to notify us that the project is in fact deployed.

I do not want to include a deploy.ps1 file in my Visual Studio project, but rather have this downloaded as part of the deployment script. I tried downloading it to the project folder when the repo is pulled from GitHub but the deployment agent log shows 'deploy.ps1 not found'.

Any idea how I can accomplish this?

  1. Support Staff 1 Posted by Feodor Fitsner on 23 Sep, 2015 06:00 PM

    Feodor Fitsner's Avatar

    Well, that's the problem that deploy.ps1 should be added to project/application package and be in the root of your web site. What if we add a setting to remove deploy.ps1 after the app is deployed?

  2. 2 Posted by Brandon on 23 Sep, 2015 06:18 PM

    Brandon's Avatar

    I think I'm actually looking for a little different scenario, I want to inject deploy.ps1 into the deployment at build time. Here's the scenario:

    1) I have a single common deploy.ps1 script that I host out somewhere (http, github, whatever) that will use the deployment variables available in appveyor and notify us (via webhook call, slack, etc that the deployment agent has deployed the package).

    2) At some point (pre-build, post-build, pre-deployment?) I need to download deploy.ps1 into wherever it needs to be for it to be packaged up.

    3) Deployment agent deploys web package, executes deploy.ps1. If it could be deleted at that point, that's great since we don't want it hanging around in the root of the web site, but mainly looking for steps 1 and 2.

    We do this today in our pre-deployment scripts that sends a nice "Deploying v1.2.3" but at that point we lose visibility over it when appveyor schedules the deployment agent job (sometimes our previous versions of the deployment agent would hang here). If we could integrate an injected deploy.ps1 or any other way of giving the deployment agent a post-deployment powershell script to run, then we would have our confirmation that it is, in fact, deployed.

  3. Support Staff 3 Posted by Feodor Fitsner on 23 Sep, 2015 06:20 PM

    Feodor Fitsner's Avatar

    OK, you can have an empty "stub" deploy.ps1 committed to the root of your app and then download/replace it with a real one before the build.

  4. 4 Posted by Brandon on 23 Sep, 2015 06:27 PM

    Brandon's Avatar

    Ah, don't always have control over the project roots before it reaches appveyor -- so in order for us to "inject" it at build time, we would need to download it to the project root at the pre-build step, and modify the .csproj file XML to reference it? That's ugly, but would that work?

  5. Support Staff 5 Posted by Feodor Fitsner on 23 Sep, 2015 06:30 PM

    Feodor Fitsner's Avatar

    Yes. To avoid modifying .csproj you can add an empty deploy.ps1 with just # do not delete comment.

  6. 6 Posted by Brandon on 23 Sep, 2015 08:39 PM

    Brandon's Avatar

    Wish I had that option on some projects, but on some I don't control them. If anybody knows any tricks to add an item to .csproj files with PowerShell I'd appreciate it!

  7. Support Staff 7 Posted by Feodor Fitsner on 23 Sep, 2015 09:22 PM

    Feodor Fitsner's Avatar

    I see, you have kind of read-only access to those repos.

    You can modify .csproj file using PowerShell. It's not necessary should be treated as XML (which is the first thing coming to head), but you can just insert something like that before the closing </project> tag:

    <Target Name="BeforeBuild">
        <Content Include="web.config" />
  8. 8 Posted by Brandon on 27 Sep, 2015 04:53 AM

    Brandon's Avatar

    For anyone else having this problem, I ended up writing a PowerShell script to inject deploy.ps1 into the project before build.

    Actual powershell injection script is here:

  9. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:00 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac