Terje Sandstrom

------ Chief Software Geek at Inmeta Consulting in Scandinavia ----- and a Visual Studio ALM MVP

  Home  |   Contact  |   Syndication    |   Login
  59 Posts | 1 Stories | 97 Comments | 0 Trackbacks

News

Subscribe

Delicious Save this on Delicious Visual Studio Feeds

¨

Tag Cloud


Article Categories

Archives

Post Categories

Image Galleries

Company stuff

Interesting bloggers

Interesting companies

Microsoft

Microsoft Norge

Microsoft Regional Directors

Microsoft Test

MSFT Blogs

MVP

NNUG

Other interesting stuff

TFS

Visual Studio

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:

  1. Install the Visual Studio SDK.  The SDK has the project templates for the VSIX
    1. Visual Studio 2010 SDK:  http://www.microsoft.com/download/en/details.aspx?id=2680 
    2. Visual Studio 11 SDK:  http://www.microsoft.com/download/en/details.aspx?id=28990 
    3. When you install the SDK, you get a new set of Project items under the folder “Extensibility” (1 in figure below)
  2. Add a VSIX project to the solution with your custom checkin policy
    1. SNAGHTML9e57448
    2.   Choose the VSIX Project type (2).
  3. In the VSIX project add a reference to your custom checkin policy project
    1. image
  4. You then should add some items to the project, but only one of these is mandatory:
    1. image
    2. Item #1 is an icon bitmap.  Nice to have, but optional
    3. Item #2 is a license text document. Nice to have, but optional
    4. 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.
      1. You just add a text file, and name it policies.pkgdef.  The name can be anything, but the extension should be “pkgdef”.
  5. Edit the policies.pkgdef to look like this:
    1. [$RootKey$\TeamFoundation\SourceControl\Checkin Policies]
      "Inmeta.TFS.CheckinPolicies"="$PackageFolder$\Inmeta.TFS.CheckinPolicies.dll"     (Copy paste from this)
      image
      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. image
  6. 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.
    1. VS2010:  Using the editor to set up the manifest

image

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.

SNAGHTMLa280755

3) You have to add the policies.pkgdef file as Content to the manifest.

SNAGHTMLa265fe0

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">
  <Identifier Id="Inmeta.CheckinPolicies11.VSIX..69ec79aa-3c86-492e-b440-decf901288e4">
    <Name>Inmeta.CheckinPolicies11.VSIX</Name>
    <Author>Inmeta Consulting AS</Author>
    <Version>1.437</Version>
    <Description xml:space="preserve">Inmeta Checkin Policies for Visual Studio 11</Description>
    <Locale>1033</Locale>
    <MoreInfoUrl>http://intranet.osiris.no/knowledge/Wiki%20Pages/OCPChangeLog.aspx</MoreInfoUrl>
    <License>License.txt</License>
    <Icon>ICP.bmp</Icon>
    <SupportedProducts>
      <VisualStudio Version="11.0">
        <Edition>Pro</Edition>
      </VisualStudio>
    </SupportedProducts>
    <SupportedFrameworkRuntimeEdition MinVersion="4.0" MaxVersion="4.0" />
  </Identifier>
  <References />
  <Content>
    <VsPackage>policies.pkgdef</VsPackage>
  </Content>
</Vsix>

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.

 

Finishing it: 

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.

 

Notes:

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:

image

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:

image

 

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.

posted on Saturday, March 10, 2012 9:54 PM

Feedback

# re: Packaging custom checkin policies for Visual Studio using VSIX 5/7/2012 4:11 PM daniel
Very nice example but what about when you want to update the policy with a new version?

# re: Packaging custom checkin policies for Visual Studio using VSIX 6/16/2012 12:30 PM Deef
Should this work for 2012 RC?

# re: Packaging custom checkin policies for Visual Studio using VSIX 6/21/2012 4:12 PM Oren Micha
Very well Done.

I would add the location of the Dll folder
(where the assembly's location will - $PackageFolder$ )

# re: Packaging custom checkin policies for Visual Studio using VSIX 6/26/2012 7:23 PM Dan Minguez
Great detail! Thanks a lot for this post, it was a time saver for me.

# re: Packaging custom checkin policies for Visual Studio using VSIX 8/31/2012 12:47 AM Terje
Daniel: You update the version number field in the manifest file.
Deef: It works for RC and RTM


# re: Packaging custom checkin policies for Visual Studio using VSIX 10/17/2012 2:02 AM Daniel Schroeder
"There are guidelines on the net on how to use assembly binding redirection to make VS 11 use VS 2010 assemblies."
I did some quick searching, but can't find any sites that show how to do this. Do you have a link? We need our policies to work in both 2010 and 2012 until we can get everybody upgraded to 2012 (will take about a year), so I don't want to straight-up convert our policies to 2012 yet.

# re: Packaging custom checkin policies for Visual Studio using VSIX 10/21/2012 8:58 PM Terje
Yup, that worked. I also found this post (http://social.msdn.microsoft.com/Forums/en-US/tfspowertools/thread/b9eccbe6-9424-44f8-8d89-8695d7f4499a ) which describes the same sort of process

Thanks!

Dan

From: Sandstrøm, Terje
Sent: October 16, 2012 6:44 PM
To: Daniel
Subject: RE: Comment: re: Packaging custom checkin policies for Visual Studio using VSIX (via Terje Sandstrom)

Hi !

I don’t think you need to use the binding redirection to make this work. We don’t.
We have used the following procedure in several cases now, with both TFS 2010 and TFS2012 and it seems to work. I say “seem”, because I have not explicitly checked exactly the how and why here.

1. Create one installer for each, VS 2010 and VS 2012.
a. The VS2010 you already got
b. The VS2012, use exactly the same code, just compile it against the new 2012 assemblies.
2. In cases where the devs have both VS2010 and VS2012 on the same machine, install both. They will work side by side, and will be installed into separate directories for each toolset.
3. Now the “trick” to make this work:
a. Use VS 2012, and open up Team Explorer
b. For each project, open up Settings/Source control
c. Delete the existing checkin policies, and Add the same again.

You will now have the 2012 serialized representations in the TFS. These are backward compatible (it seems, which makes sense too), so they will also work with VS 2010. Note that what you “Install” in these TFS settings are not the binaries, but some serialized representation of the checkin policies. I guess you have noticed that all the checkin policies you write have to be serializable.
My guess is that there are some differences in the representation for 2012, which are expansions of that representation. This then works in 2010 because that one expects a smaller serialization. I will check this more up when time allows……

You might have to restart VS.

I am not sure if this step 3 is needed in all cases, or just for custom checkin policies. We have just done this, and then it has worked afterwards. I am not even quite sure (can’t remember) if you need to do this for all team projects or just for one.



Post A Comment
Title:
Name:
Email:
Comment:
Verification: