Taking Visual Studio build and publish events to the next level

2017: Why is this post so popular? It’s always one of the highest viewed posts on my site and I’ve never understood why. When you’re done reading, please leave a comment letting me know.

I just integrated Visual Studio’s web project publish command with Zapier  so I can send build events to Slack.

That’s a twofer, folks. I just killed two birds with one really awesome stone.

Seriously, the possibilities here will blow your mind, especially given how easy it is to make it happen.

First, I’ll explain how I hooked into the publish event. If you’re more interested in the Zapier part, feel free to skip to the next section.

The web project publish event

Hooking into the Visual Studio 2013 web project publish event isn’t the most obvious thing in the world. In fact, I couldn’t easily find anything on the bings to show me how to do it.

Just to clarify, by “Visual Studio 2013 web project publish event”, this does not have anything to do with a ClickOnce publish. What  I mean is that I want to perform some special upon completion of the process that executes whenever you right-click on a web project and select “Publish…”. I.E….

To achieve the desired outcome is simple once you know what to do. Just place this somewhere near the bottom of your .csproj file (inside <project></project>):

$(DestinationAppRoot)  is the name of the publish profile you selected. That’ll come in handy in the second part of this post.

Publish and build events with Zapier

This part was mind-numbingly easy.

If you’re not familiar with Zapier, it’s a service that “connects the web apps you use to easily move your data and automate tedious tasks….. Connect the apps you use to easily move data between them.” 300+ apps at the time of this writing, by the way. It’s similar to IFTTT except more business oriented in my opinion.

You can’t appreciate how awesome this is until you learn more about Zapier. Please, if you really haven’t heard of Zapier, take time to go look at the Zapier site now and come back when you’re super excited.

In my case, I want to send a Visual Studio publish event to Zapier so I can forward it to Slack.

To do this, we’re going combine the publish event instructions above with Zapier’s ability to catch webhooks.

All you need is curl (easily installed with Chocolatey here) and a Zapier account.

I’m not going to go into all of the details of setting up a webhook event in Zapier… The Zapier website makes that very easy.

Instead, I’ll show you the magic…

And here’s the magic…

Here’s how I’ve configured Zapier to send the “Action” parameter above to Slack:

And it works…

As you can imagine, this Zapier integration via curl could really be done anywhere in Visual Studio, including before/after build events, for example.

just made this work in Visual Studio and I’m super pumped about the possibilities! I could literally have my publish events flash the lights in my house via Homeseer…


  • Bobby Cannon

    How does this affect build times? Also what happens if Zapier is down?

    • I only use this on publish, currently. That’s a longer, more rare process to begin with, so I don’t particularly care if it adds a little time. In my tests so far though, curl only takes about a second or two to complete.

  • Bobby Cannon

    I’m also in the process of automating my house using a Vera Lite and custom code.

    • Vera Lite is awesome, too. I opted for Homeseer because I can write .NET plugins for it. And I already had a computer I could run the software on.. and the software was 50% off at the time ($300 instead of $600).

    • Side note.. my wife let me buy six Philips Hue lights yesterday. She didn’t think she’d like it… but then she spent half a hour building different colored scenes once she saw how cool it is. :)

  • What about getting 10$ bamboo, or teamcity for free, and make them publish your web project and talk to slack? Afaik, bamboo supports jabber, or u could’ve just run ur cmd as last step of build.

    • Bamboo and Teamcity’s publish isn’t the same as Visual Studio’s publish. Not sure what jabber has to do with anything. And I don’t want to talk to Slack at the end of my build – I want to talk to Slack at the end of my publish.

  • Gareth Hopkins

    Is there a list of the $(xx) variables anywhere? I’m looking for one that will give me the Publish Profile’s destination URL but can’t guess it and can’t find any docs

    • I don’t know, honestly. Try searching your entire hard drive for ‘DestinationAppRoot’ and you might stumble across something useful. I don’t really remember how I came up with the solution posted here. :)

      • Gareth Hopkins

        :) thanks. Seems to be nothing online!? Soo useful though, thanks for posting.

  • Peter

    Is it possible to use the AfterTargets when WebPublishMethod is set to FileSystem?

    I am trying a Target to Exec a command but VS2013 does not recognise when publishing with this method.

    Has anyone tried this or have a workaround?

    • Sorry, Peter, I haven’t tried to do this. I might have an opportunity this weekend to experiment, so I’ll let you know if I discover anything.

    • Javier Espinoza

      Hello Peter. This might be 5 months late, but for others that need an AfterTargets for FileSystem method, this works: (although it executes before copying the files)