NOTE: All code and instructions in this blog post were updated to work with the latest version of Web Deploy v1.1. A blog post that outlines the changes that are required to custom providers in Web Deploy v.1.1 since Web Deploy v1 RC is here.
Overview
The IIS Web Deployment Tool (also known as MSDeploy) simplifies the migration, management and deployment of IIS Web servers, Web applications and Web sites. MSDeploy also offers the ability to run custom providers. These providers unlock hidden power in MSDeploy.
In this article you will find a sample code for a custom MSDeploy provider that executes batch file commands as a part of MSDeploy sync. The batch file provider can be used to execute custom scripts before or after deployment to make the deployment process a seamless one. You can set up performance counters for a particular MSDeploy sync, make a batch file copy content with xcopy rather than with MSDeploy (but remember that we’re faster than xcopy!) to name just a few possibilities. The code in this article is meant as a sample to get you started on writing your own custom MSDeploy provider. This provider is similar to MSDeploy runCommand provider with the exception that this custom provider does not have the full set of features the official MSDeploy runCommand provider does. In any case, the code is built thankfully to a great sample and blog that Yamini Jagadeesan wrote a couple of months ago on MSDeploy MySql custom provider that lets you sync from one MySql database to another. If you haven’t familiarized yourself with the article, it is a great read and another good start-up solution for MSDeploy custom provider.
Download and Install
First, download the zip file with the projects (also contains Yamini’s MySql custom provider). BatchProvider solution contains the following files:
- BatchProviderFactory.cs – an entry point to your provider that kindly returns an instance of the provider in overridden CreateProvider method.
- BatchProvider.cs – the provider itself that initiates execution of a batch file.
- Strongname.pfx – the file with a key to sign the assembly for strong name verification. The password is “MSDeployRocks”, but you can delete the pfx file and specify your own key and password for singing the assembly by going to Project Properties-->Signing in Visual Studio.
To install the provider you need to
- Compile the project (or just use this dll)
- Create a folder called Extensibility under “%programfiles%\IIS\Microsoft Web Deploy”. This folder will contain all your MSDeploy custom providers
- Drop the dll into the newly created folder
MSDeploy is ready to work with the new provider.
The Internals of BatchProvider
You can tweak the provider to suit the task you have in mind. For example, you might want to tweak ProcessStartInfo of the process that will execute the batch file commands to control its behavior during sync. You might want to redirect output and error streams of the process to log the results of execution.
Please feel free to post any comments and questions.
Thanks to Yamini for pointing out these differences between MSDeploy versions.