The text of this article is not in this database — only its details are. The old site it was published on is gone, but the Internet Archive kept a copy: Introduction to Visual Studio Add-ins
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Gowtham RajamanickamPosted Apr 19, 2016, 6:42 AM
very good article
Peter PhelpseditedPosted Mar 28, 2009, 10:37 AMEdited Mar 28, 2009, 1:58 PM
Thanks for the article. It was very interesting. I have a few comments to hopefully make it easier for others, and one question. First, the code is missing a using System.IO; statement at the top. This allows access to the Path and StreamWriter classes, etc. Next, and more importantly, the code does not check to see if these events were already added. So if the user can't remember if he already started this add-in, starting it again causes the event to be triggered an additional time for each build, which muddies up your logfile. To resolve this, I tried to "walk" the event list while in the Exec() method, but couldn't figure out how to do so. Ultimately I decided on a simple bool to determine if the code has already done its job. To make the changes, do the following: At the top of the class declare a bool: public class Connect : IDTExtensibility2, IDTCommandTarget { bool EventsAdded = false; ... Then wrap the event modification code found in Exec() in a simple if statement and tweak your bool when it executes: if(commandName == "SampleAddIn.Connect.SampleAddIn") { handled = true; if(!EventsAdded) { _applicationObject.Events.BuildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(BuildEvents_OnBuildBegin); _applicationObject.Events.BuildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(BuildEvents_OnBuildDone); EventsAdded = true; } return; } This code only works because it holds the state of the bool in the class, so I consider it a bit of a hack. I think it would be a lot better if the code somehow determined if the event had already been set by walking an event list, but I have no idea how to do that programmatically. If anyone wants to explain that one to me, I'll put you in my will! A final thing worth mentioning is how Add-ins are stored by the IDE. The location of your compiled Add-ins are in the folder you specified at Tools/Options/Projects & Solutions/General --> Visual Studio projects location. To remove an Add-in: Shut down the IDE, and then either delete or move a given add-in. It will not be available at IDE restart. If you just want to not use an add-in, then go to Tools/Add-in Manager... and uncheck the Startup Box. The source folder for the Add-in is just like any other source folder, and can just be deleted. Hope this helps! --Pete
James GregorPosted Mar 16, 2009, 8:42 AM
If you're as careful as me, you will be logged into your Windows system as a limited user. In this case, you will not have access to the root directory C:\ and you will not be able to create the output file "sampleprojectname.txt". A better soultion would be to change control.cs so that it creates the file in C:\TEMP. Of course there are other good dirctory choices, but this one is easy.
Eric SanderseditedPosted Mar 4, 2009, 4:13 PMEdited Mar 4, 2009, 4:51 PM
Thanks for the tutorial! I am in the process of porting my old C++ VS6.0 addin over to VS2005 in C#. All is going well except for one snag. I have added te proper code to add the commands to the Tools menu, the QueryStatus function, as well as the Exec function, and removed references to the default wizard generated command. When I run in debug mode, I see my five command icons in the tools menu. If I select the AddIn Manager option to load on startup, I only see the original default command created by the wizard, even though I removed it from the connect.cs file. Any ideas where I am faltering? Thanks, Eric Update.....found a crude solution... On instinct, I changed the line: if(connectMode == ext_ConnectMode.ext_cm_UISetup) to if(true)//connectMode == ext_ConnectMode.ext_cm_UISetup) to force it to go into the code section where my commands are added to the Tools menu. Low and behold, that worked. I changed it back and all is well. I'm sure that this little hack isn't the preferred way to do this however. Eric