Deployment of custom checkin policies can be done using either an MSI or VSIX. There are many reasons to prefer using the VSIX format. It is more lightweight, and thus more suitable for small components for VS, as it will not “pollute” the installed programs store. Further, since the Visual Studio setup projects have been cut from Visual Studio 11, the VSIX is a better choice, being supported both in VS 2010 and VS 11. VSIX is also very easy to create, once you know how, and it is very fast running too.
Jim Lamb had an excellent blog post about how to implement, package and deploy custom checkin policies using VSIX. Unfortunately that post lacks some details. Aaron Marten found some of the issues here. I have gone through both of these and in this blog post I will show the details of how you can package this in a VSIX.
Jim Lambs post fully explains how to implement a custom policy, so I will not go through that again.
In order to package it in a VSIX, follow the steps below:
- Install the Visual Studio SDK. The SDK has the project templates for the VSIX
- Visual Studio 2010 SDK: http://www.microsoft.com/download/en/details.aspx?id=2680
- Visual Studio 11 SDK: http://www.microsoft.com/download/en/details.aspx?id=28990
- When you install the SDK, you get a new set of Project items under the folder “Extensibility” (1 in figure below)
- Add a VSIX project to the solution with your custom checkin policy
- Choose the VSIX Project type (2).
- In the VSIX project add a reference to your custom checkin policy project
- You then should add some items to the project, but only one of these is mandatory:
- Item #1 is an icon bitmap. Nice to have, but optional
- Item #2 is a license text document. Nice to have, but optional
- Item #3 is a package definition file. This is mandatory, and contains instructions for setting up a registry key. This registry key is needed by Visual Studio in order to find and load the checkin policies.
- You just add a text file, and name it policies.pkgdef. The name can be anything, but the extension should be “pkgdef”.
- Edit the policies.pkgdef to look like this:
"Inmeta.TFS.CheckinPolicies"="$PackageFolder$\Inmeta.TFS.CheckinPolicies.dll" (Copy paste from this)
Part 1: This is a name you choose to give your policy package, and which will be the name of the key in the registry
Part 2: This is the assembly name as defined in the project properties, Application/Assembly name field.
- At last you have to set up the vsixmanifest file, the one named source.extension.vsixmanifest. In VS 2010 there is an editor for that file, but in VS 11 Beta the editor is not there, and you must edit the file yourself. It can be an easy way out to make it first in VS 2010, and then open it up afterwards in VS 11. The whole VSIX project will then be upgraded to the VSIX format for VS 11.
- VS2010: Using the editor to set up the manifest
1) When you update your checkin policy, increment the version number too. This will make the VSIX updateable.
2) Select the Visual Studio editions the VSIX shall apply for. You only need to set the lowest SKU, all above are automatically allowed.
3) You have to add the policies.pkgdef file as Content to the manifest.
4) The result of the Add Content operation in 3).
5) These fields are optional. The License Terms is the name of a text or rtf file. Add one to the project and name it here. The Icons and Preview Image’s can be added, any bitmap file will do. The icon must have the right size of course. The URL field and Getting started guide can be filled in as one likes.
Now, for VS 11, the manifest must be edited as an XML file:
<?xml version="1.0" encoding="utf-8"?>
<Vsix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010">
<Author>Inmeta Consulting AS</Author>
<Description xml:space="preserve">Inmeta Checkin Policies for Visual Studio 11</Description>
<SupportedFrameworkRuntimeEdition MinVersion="4.0" MaxVersion="4.0" />
Note that you must change the Visual Studio version attribute to read “11.0”. Otherwise the rest of the fields should be easily understandable from the editor description above.
This is all you need to do. Compile it, and install the VSIX by double-clicking it. Note that it first takes effect when you restart Visual Studio.
When you port your checkin policies from VS 2010 to VS 11, be aware that you change the references from pointing to the VS 2010 assemblies to point to the new VS 11 assemblies.
In our case we had these assemblies:
You may have more or less than these, dependent upon what kind of custom checkin policies you have made.
Also note that one checkin project can contain many checkin policies. Our package contains these:
There are guidelines on the net on how to use assembly binding redirection to make VS 11 use VS 2010 assemblies. This is also a way to go, but I prefer to convert them to VS 11 proper.