Copy Source as Html in Visual Studio 2010

Posted Friday, November 20, 2009 1:33 PM by CoreyRoth

I was working on my first SharePoint 2010 post today since I actually installed some bits and quickly discovered that I did not have Copy Source As Html working with Visual Studio 2010 Beta 2.  If you’re a blogger like me, you will find that you are quite addicted to this useful tool as it makes pasting good looking code segments quite easy.  Unfortunately, they haven’t released an installer that works with Visual Studio 2010 yet, so I decided to see if I could figure out how to get it to work.  Now, I’m not expert on Visual Studio Addins, so it took me some experimenting.  I installed the product as normal, but when I opened Visual Studio, I did not find the addin loaded.  After some investigating, I decided to copy the CopySourceAsHtml.AddIn file into my user folder.  Specifically this goes in C:\Users\<UserName>\My Documents\Visual Studio 2010\Addins.  Note: the My Documents folder is actually the Documents folder if you are looking at it directly on the file system.  Also to note is that the Addins folder probably will not exist so you need to create it.

After I did this, I tried opening Visual Studio again and again did not see my addin loaded.  I then decided to open the file and take a look.  I quickly saw something that stood out at me.

<?xml version="1.0" encoding="utf-8" 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 2008 for copying source code, syntax highlighting, and line numbers as HTML.</Description>

    <Assembly>JTLeigh.Tools.Development.CopySourceAsHtml, Version=3.0.3215.1, Culture=neutral, PublicKeyToken=bb2a58bdc03d2e14, processorArchitecture=MSIL</Assembly>

    <FullClassName>JTLeigh.Tools.Development.CopySourceAsHtml.Connect</FullClassName>

    <LoadBehavior>1</LoadBehavior>

    <CommandPreload>0</CommandPreload>

    <CommandLineSafe>0</CommandLineSafe>

  </Addin>

</Extensibility>

This is version 10 of Visual Studio so I decided to increment the new two version elements as shown below.

<?xml version="1.0" encoding="utf-8" standalone="no"?>

<Extensibility xmlns="http://schemas.microsoft.com/AutomationExtensibility">

  <HostApplication>

    <Name>Microsoft Visual Studio Macros</Name>

    <Version>10.0</Version>

  </HostApplication>

  <HostApplication>

    <Name>Microsoft Visual Studio</Name>

    <Version>10.0</Version>

  </HostApplication>

  <Addin>

    <FriendlyName>CopySourceAsHtml</FriendlyName>

    <Description>Adds support to Microsoft Visual Studio 2008 for copying source code, syntax highlighting, and line numbers as HTML.</Description>

    <Assembly>JTLeigh.Tools.Development.CopySourceAsHtml, Version=3.0.3215.1, Culture=neutral, PublicKeyToken=bb2a58bdc03d2e14, processorArchitecture=MSIL</Assembly>

    <FullClassName>JTLeigh.Tools.Development.CopySourceAsHtml.Connect</FullClassName>

    <LoadBehavior>1</LoadBehavior>

    <CommandPreload>0</CommandPreload>

    <CommandLineSafe>0</CommandLineSafe>

  </Addin>

</Extensibility>

After I saved the changes, I restarted Visual Studio and sure enough the addin loaded and worked correctly.  In fact I pasted the above snippets using the tool in Visual Studio 2010.  If you have never used Copy Source as Html before, go check it out.  It’s a handy tool for pasting code snippets.

Filed under:

Comments

# re: Copy Source as Html in Visual Studio 2010

Saturday, November 21, 2009 10:29 AM by Prasanna

Great tip, thanks for sharing.

# re: Copy Source as Html in Visual Studio 2010

Wednesday, February 3, 2010 11:45 AM by Mark Seemann

Worked like a charm - thanks so much!

# The second problem of Visitors

Sunday, May 9, 2010 12:29 PM by Fabian's Mix

The second problem of Visitors

# re: Copy Source as Html in Visual Studio 2010

Friday, May 21, 2010 3:52 PM by David Worsham

Thanks.  Didn't think to edit the file.

# Copy source as Html in Visual Studio 2010 &laquo; Philippsen&#039;s Blog

Pingback from  Copy source as Html in Visual Studio 2010 &laquo; Philippsen&#039;s Blog

# re: Copy Source as Html in Visual Studio 2010

Friday, March 4, 2011 4:27 PM by Ryan

You saved me a lot of time.  Thanks!

# re: Copy Source as Html in Visual Studio 2010

Tuesday, April 12, 2011 1:57 PM by Dave Black

Cool!  Thanks for reminding me about this!  I've seen this behavior in other add-ins in the past and fixed it for them - just forgot how to do it though...

# re: Copy Source as Html in Visual Studio 2010

Tuesday, July 5, 2011 3:21 AM by Srini

Excellent idea . Helped me a lot.

Leave a Comment

(required)
(required)
(optional)
(required)