Click here to Skip to main content
Click here to Skip to main content

Building a Shared Code Library as a VS.NET Plug-in

, 30 Mar 2005
Rate this:
Please Sign up or sign in to vote.
A plug-in for VS.NET that stores code snippets in a database. From the plug-in you can add code, search the database for code snippets. Also includes examples on how to integrate with the IDE as a plug-in.

Introduction

The "CodeManager" is a plug-in for VS.NET that stores code snippets in a database. From the plug-in you can add code, search the database for code snippets to insert into your code. That is really the core of it. The reason why I took all the effort of creating this, was that we (the developer collective) needed a way to share code in our organization. Hence, one very misspent vacation, writing this! In an attempt to justify the time spent on it, I am now inflicting it upon you.

Having done some analysis on what was out there (looking to buy a third party solution - turns out they were overpriced), I thought I could get similar results in just a few days, at a fraction of the cost. I built this during a short vacation over an year ago, hence the code quality is not something I would be proud of, but it does the job it was designed to. To me its a good example of re-use, and leveraging code/classes that already exists, and was able to reduce the development time by orders of magnitude.

This would be interesting to you if;

  • You want to learn how to create a real world VS.NET plug-in.
  • You need a shared code library that you can maintain and extend internally.

Here are a couple of screenshots of it in action:

Adding code to the library

Searching for code

Background

This book gave me some crucial tips in order to get this done quickly: Writing Add-ins for Visual Studio .NET.

I have used and extended the code from Julijan's add-in to include a versioning controlled build in the project, as detailed in the article Versioning Controlled Build.

Using the code

You can either use the installation and DB script to set up a working installation, or set up the code in your IDE. I recommend the latter, though it requires more effort it gives you the opportunity to really examine what is going on.

The overall concept is the same for using ToolWindows in .NET. The VSUserControlHost DLL needs registering (if you don't go through the installer). This is then used to host a usercontrol, which contains all the functionality for the ToolWindow (as seen in the main screenshot). This user control presents an interface to SQL Server database which contains code snippets. Other integration points are the main menu entries, the toolbar entries, an Options dialog and the output windows (all are displayed below in images). Users are validated using Windows Authentication/Active Directory and added dynamically. I have also included an updated version of the version updater (sorry about that sentence), as listed in the references by Julijan Sribar.

The Context Menu

The Main Menu

The Output window

Toolbar items

Setting up

  • You need a SQL DB server to use. Create a database, call it RADDev, and install the supplied script there.
  • You also need to register VSUserControlHostLIb - the project is provided with the code. Open a command prompt, navigate to the folder where the VSUserControlHost.dll is, and type in regsvr32 VSUserControlHost.dll.
  • Now, open the solution, and you will see three projects.
  • WinUserControlTestProject - this is the project used to test the functionality in the main user control during development. It is convenient while testing add-ins to have a separate test application to test the core functionality, as reloading the add-in becomes a drain on debugging time.
  • RadDevSetup - this is the setup program, which builds the redistributable. Nothing remarkable about this.
  • Lastly, RadDev - this is the add-in project itself, which does have lots of interesting things about it.

Points of interest

  • clsCodeDBFunctions – this interfaces with the data accessor class below clsDBTier – this is an accessor block type class. It is quite out of date now, but it still does the job.
  • clsNodeTag: This stores the information for a tree node, it is just a holder class (should probably be a struct, but who knows what more needs to be added in the future).
  • clsRegistration – handles registration of licenses, new users, and decrypts licenses for checking. The registration isn't being checked anymore in the current code set. The build I made for the company was limited to the company's domain.
  • clsWinAuthentication – this class authenticates the user against their Windows domain and user, then checks against the database to see if they have been already added. If they are a new user, they are prompted to enter more details, and subsequently added to the database. It is important to know who is adding articles, as only the user who has added can delete it. Also I have written controls in ASP.NET applications that create content based on the contents of the database, so you need names for the articles.
  • Crypto.vb – this is used for encryption/decryption of license keys. All credit for this goes to Stan Schultes.
  • I am not going into greater details of the code as it is a lot interesting, but nothing in particular stands out to me. You really need to pick out the things that interest you the most from the code set itself.

History

It really needs a thorough cleaning up in terms of removing unused code. What it needs the most is someone who really needs this tool, to take ownership of it (I have too many other projects/commitments), and do a cleaning and rinsing on it. Hence I am freeing it to the world. There are lots and lots of areas where it can be improved. There are some redundant classes, like VSS integration and maintain database versioning, which are still good ideas, but could not make it into this version. My plan was to create a tool that also did integrated change management, linking to a web based system that I was already using. I think there is a call for an open source plug-in that covers these areas. I believe the market prices of the commercial options are over-priced.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

paul heap
Web Developer
Thailand Thailand
Spent my whole life developing, having worked in C++, Delphi, ASP, then finally settling down to working solely in ASP.Net. Also a forex day trader.

Comments and Discussions

 
Questionabout you! PinmemberConHulio12-Jun-13 9:48 
Generalplease move to a new database :) PinmemberJoe Robe27-Jul-05 16:31 
GeneralTry to get it to work PinmemberHaichih Hwa14-Apr-05 11:21 
GeneralRe: Try to get it to work PinmemberkScope14-Apr-05 22:56 
Generalnot able to set database settings in Raddev option Pinmemberashu_sharma2112-Apr-05 1:07 
QuestionHow to get it working PinmemberSteve Hurcombe8-Apr-05 2:00 
AnswerRe: How to get it working Pinmemberpaul heap12-Apr-05 6:32 
GeneralWrite DRY Code PinmemberAl Einstien4-Apr-05 8:23 
GeneralRe: Write DRY Code Pinmemberpaul heap4-Apr-05 18:29 
GeneralRe: Write DRY Code PinmemberDot Netter5-Apr-05 14:44 
I agree with your comment entirely. However, I wrote myself a tool much like this, myself. Not because I like the idea of having code snippets I can copy and paste, but to have purely as an algorithm reference. I would have a category for "Sorting Algorithms" for example, in which I would have some implementation of a Bubble Sort, a Merge Sort, etc... It would just be a reference, and more like a Knowledge Base than a whole lot of code I could re-use in production. Maybe it's different in that respect, because the code in there was always written to be "illustrative and educational" rather than "off the shelf reusable."
GeneralDoesn't work :-( PinmemberNiteman4-Apr-05 0:18 
GeneralRe: Doesn't work :-( PinsussAnonymous4-Apr-05 0:41 
GeneralWiki PinprotectorMarc Clifton1-Apr-05 1:53 
GeneralRe: Wiki Pinmemberpaul heap1-Apr-05 18:18 
Generaldatabase user PinmemberEYH31-Mar-05 9:15 
GeneralRe: database user Pinmemberpaul heap31-Mar-05 18:35 
GeneralRe: database user PinmemberLevi.Rosol1-Apr-05 6:56 
GeneralRe: database user Pinmemberpaul heap1-Apr-05 18:37 
GeneralRe: database user PinmemberkScope6-Apr-05 6:58 
GeneralRe: database user Pinmemberpaul heap6-Apr-05 20:01 
GeneralRe: database user PinmemberkScope8-Apr-05 7:02 
GeneralNo Code Pinmemberjhidey31-Mar-05 2:58 
GeneralRe: No Code Pinmemberpaul heap31-Mar-05 4:33 
GeneralRe: No Code Pinmemberpaul heap31-Mar-05 4:43 
GeneralUpdates to download Pinmemberpaulinthailand30-Mar-05 21:53 
GeneralRe: Updates to download PinmemberLevi.Rosol1-Apr-05 6:53 
GeneralRe: Updates to download Pinmemberpaul heap1-Apr-05 18:28 
GeneralRe: Updates to download Pinmemberpaul heap1-Apr-05 18:57 
GeneralRe: Updates to download Pinmembermaimoy8-Apr-05 6:22 
GeneralRe: Updates to download PinmemberkScope8-Apr-05 6:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 31 Mar 2005
Article Copyright 2005 by paul heap
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid