Click here to Skip to main content
15,881,139 members
Articles / Web Development / HTML
Article

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

Rate me:
Please Sign up or sign in to vote.
4.00/5 (7 votes)
30 Mar 20055 min read 89K   594   41   30
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

Image 1

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:

Image 2

Adding code to the library

Image 3

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.

Image 4

The Context Menu

Image 5

The Main Menu

Image 6

The Output window

Image 7

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


Written By
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! Pin
ConHulio12-Jun-13 8:48
ConHulio12-Jun-13 8:48 
Generalplease move to a new database :) Pin
Member 21894927-Jul-05 15:31
Member 21894927-Jul-05 15:31 
GeneralTry to get it to work Pin
Member 153733614-Apr-05 10:21
Member 153733614-Apr-05 10:21 
GeneralRe: Try to get it to work Pin
kScope14-Apr-05 21:56
kScope14-Apr-05 21:56 
Generalnot able to set database settings in Raddev option Pin
ashu_sharma2112-Apr-05 0:07
ashu_sharma2112-Apr-05 0:07 
QuestionHow to get it working Pin
Steve Hurcombe8-Apr-05 1:00
Steve Hurcombe8-Apr-05 1:00 
AnswerRe: How to get it working Pin
paul heap12-Apr-05 5:32
paul heap12-Apr-05 5:32 
GeneralWrite DRY Code Pin
Tad McClellan4-Apr-05 7:23
professionalTad McClellan4-Apr-05 7:23 
GeneralRe: Write DRY Code Pin
paul heap4-Apr-05 17:29
paul heap4-Apr-05 17:29 
GeneralRe: Write DRY Code Pin
User 913735-Apr-05 13:44
User 913735-Apr-05 13:44 
GeneralDoesn't work :-( Pin
Niteman3-Apr-05 23:18
Niteman3-Apr-05 23:18 
GeneralRe: Doesn't work :-( Pin
Anonymous3-Apr-05 23:41
Anonymous3-Apr-05 23:41 
GeneralWiki Pin
Marc Clifton1-Apr-05 0:53
mvaMarc Clifton1-Apr-05 0:53 
GeneralRe: Wiki Pin
paul heap1-Apr-05 17:18
paul heap1-Apr-05 17:18 
Generaldatabase user Pin
Member 31208131-Mar-05 8:15
Member 31208131-Mar-05 8:15 
GeneralRe: database user Pin
paul heap31-Mar-05 17:35
paul heap31-Mar-05 17:35 
GeneralRe: database user Pin
Levi Rosol1-Apr-05 5:56
Levi Rosol1-Apr-05 5:56 
GeneralRe: database user Pin
paul heap1-Apr-05 17:37
paul heap1-Apr-05 17:37 
GeneralRe: database user Pin
kScope6-Apr-05 5:58
kScope6-Apr-05 5:58 
GeneralRe: database user Pin
paul heap6-Apr-05 19:01
paul heap6-Apr-05 19:01 
GeneralRe: database user Pin
kScope8-Apr-05 6:02
kScope8-Apr-05 6:02 
GeneralNo Code Pin
johnhidey31-Mar-05 1:58
johnhidey31-Mar-05 1:58 
GeneralRe: No Code Pin
paul heap31-Mar-05 3:33
paul heap31-Mar-05 3:33 
GeneralRe: No Code Pin
paul heap31-Mar-05 3:43
paul heap31-Mar-05 3:43 
GeneralUpdates to download Pin
paul heap30-Mar-05 20:53
paul heap30-Mar-05 20:53 

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

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