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 to 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, so that you do not have to wait for the MSDeploy RTW release (Rumor has it that the MSDeploy team is going to have a batch file provider in RTW release). 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.
Needed for this Walkthrough
To walk through installation of the provider, you might need to download gacutil to add the assembly to the GAC. You can get gacutil as a part of .NET Framework SDK or download it separately.
Download and Install
First, download the zip file with the project. 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)
- Add the new assembly to the GAC by executing
gacutil /if BatchProvider.dll
- Register the assembly in the registry by adding a string value under
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\1\Providers\batch
The string value should point MSDeploy to your DeploymentProviderFactory, your namespace and, finally, your provider with assembly info. For the batch provider, the following string registry value needs to be added: “MSDeployCustomProviders.BatchProviderFactory, BatchProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a0b65de31a9f7a07, processorArchitecture=MSIL", where
- MSDeployCustomProviders – is the namespace containing both the factory and provider, and
- BatchProviderFactory – is the factory, and
- BatchProvider + the rest – assembly info, which you can get by running the following:
gacutil /l BatchProvider
For your convenience, register.bat is provided to do both (which runs every time the project is compiled according to project properties: in Visual Studio go to Project Properties-->Build Events and see that register.bat is called as a Post-Build event)
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.
Comments