VSIP SDK 2003 and Visual Studio SDK 2005

If you are programming a managed package for VS 2003 and you want to port your package in order to work with VS 2005 you have to use the new VS SDK for 2005.

In the VS SDK documentation there is an article How to: Migrate Managed VSPackage Source Code  that explains how to migrate your code.

After you do that you have a new problem: you have to maintain 2 copies of the same (logically are the same) files. What's the differences  just some namespaces, some constants, methods changes its namespace or container class, etc.

I'm in charge of 8-10 packages and some time ago I decided to have a branch in my source control for each migrated file. Obviously, I had problems, every file that was shared between 2003 and 2005 is updated automatically but the branched files...

So I decided to solve this problem having just one copy for each file and reduce the number of branched files. Most cases are really easy to solve(Probably I was lazy the first time I did the migration ;)

I choose to include a new file ForwardCompatibility.cs in the VS 2003 projects that basically maps the new and old names.

I mean:

public class VSConstants

{

public static readonly int S_OK = NativeMethods.S_OK;

public static readonly int E_FAIL = NativeMethods.E_FAIL;

public static readonly int E_NOTIMPL = NativeMethods.E_NOTIMPL;

public static readonly int S_FALSE = NativeMethods.S_FALSE;

...

..

}

public class Win32Methods

{

public static IntPtr SetParent(IntPtr hWnd, IntPtr hWndParent)

{

return NativeMethods.SetParent(hWnd, hWndParent);

}

}

So If you include the ForwardCompatibility.cs in your VS2003 projects you can develop your package with the new API.

Another key point are the using clauses that you can solve using defines. Personally I had a VS2005 define for 2005 packages so after I

use the following code in each file:

#if VS2005

 using MSVSIP = Microsoft.VisualStudio.Shell;

#else

using ForwardCompatibility;

using Microsoft.VisualStudio.VSIP;

using MSVSIP = Microsoft.VisualStudio.VSIP.Helper;

#endif

The ForwardCompatibility.cs it is not complete so probably you should add more stuff in order to work with your particular case. It contains the most common cases so it is a beginning.

 

 

No Comments