Thursday, August 16, 2007
After writing up this post, I found similar instructions elsewhere. Oh well... you can't always be first.

CopySourceAsHtml on the context menu of Visual Studio's editorCopySourceAsHtml is an extremely useful Visual Studio add-in that places a new menu item on the context menu of the editor. This is especially helpful for bloggers looking for an easy way to get rich source code highlighting into their blogs.

In general, I usually find it necessary to massage the HTML results a bit to get code to look good in RSS feeds, but it is far easier than, say, manual highlighting.

Yesterday, while working on my Art of Currying article, I found it necessary to highlight some C# 3.0 code and was disappointed to find that the trusty "Copy As HTML..." menu item wasn't available. Fortunately, it's very easy to install the add-in into Visual Studio 2008 beta 2.

The CopySourceAsHtml installer drops four files in the "My Documents\Visual Studio 2005\Addins" directory:

  • CopySourceAsHtml.AddIn -- an XML file that describes the add-in and is used for registration with Visual Studio.
  • CopySourceAsHtml.dll -- the add-in itself.
  • CopySourceAsHtml.dll.config -- a configuration file that contains various user settings.
  • CopySourceAsHtml.pdb -- debugging symbols for the add-in. This really isn't needed but it doesn't hurt anything either.

Simply copy these files to the "My Documents\Visual Studio 2008\Addins" directory. If the "Addins" subdirectory doesn't exist, just create it. If you are using Windows Vista, substitute "Users\CURRENTUSER\Documents" for "My Documents".

Next, in a text editor, open the CopySourceAsHtml.AddIn file that you just copied and change the two <Version> tags from 8.0 to 9.0. When you're finished, it should look like this:

<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<
Extensibility xmlns="http://schemas.microsoft.com/AutomationExtensibility">
  <
HostApplication>
    <
Name>Microsoft Visual Studio Macros</Name>
    <Version>9.0</Version>
  </
HostApplication>
  <
HostApplication>
    <
Name>Microsoft Visual Studio</Name>
    <
Version>9.0</Version>
  </
HostApplication>
  <
Addin>
    <
FriendlyName>CopySourceAsHtml</FriendlyName>
    <
Description>Adds support to Microsoft Visual Studio 2005 for copying source code, syntax highlighting, and line numbers as HTML.</Description>
    <
Assembly>CopySourceAsHtml.dll</Assembly>
    <
FullClassName>JTLeigh.Tools.CopySourceAsHtml.Connect</FullClassName>
    <
LoadBehavior>1</LoadBehavior>
    <
CommandPreload>0</CommandPreload>
    <
CommandLineSafe>0</CommandLineSafe>
  </
Addin>
</
Extensibility>

Save the file and... your're done! Start up Visual Studio 2008 beta 2, and that handy context menu item is now available and works great.

posted on Thursday, August 16, 2007 8:03:44 AM (Pacific Standard Time, UTC-08:00)  #    Comments [1]

kick it on DotNetKicks.com