---
title: "Writing a VS.Net Add-in, ugh"
url: "https://osherove.com/blog/2004/6/12/writing-a-vsnet-add-in-ugh.md"
canonical: "https://osherove.com/blog/2004/6/12/writing-a-vsnet-add-in-ugh.html"
published: "2004-06-12T14:01:00"
updated: "2004-06-12T14:01:00"
tags: [".Net Original"]
author: "Roy Osherove"
description: "I've been dabbling a bit with the notion of creating a Regulator Add-in for VS.Net. Still not sure what exactly it will feature - got any suggestions? Anyway - I don't have much experience with writing Add-ins for…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Writing a VS.Net Add-in, ugh

By Roy Osherove June 12, 2004 In [.Net Original](https://osherove.com/blog/category/net-original)

**Historical article** · Originally published June 12, 2004; technical details may be outdated.

I've been dabbling a bit with the notion of creating a Regulator Add-in for VS.Net. Still not sure what exactly it will feature  - got any suggestions?

Anyway - I don't have much experience with writing Add-ins for vs.net so I happily started one project. Boy - it should **not** be this hard. Even trying to do something as simple as creating a tool window in Vs.Net is really hard.

All the interfaces and extensibility model of VS is still in set in the wayback machine  - meaning COM interfaces and ActiveX galore.

I wonder - when will COM be like COBOL? (And will we call it “COMOL“?)

Anyway - to make a short story long and unreadable, the only way to make a tool window in VS.Net that features your .Net control is to make it host an ActiveX host control. That means you need to make an ActiveX control that will **host** your own .Net managed user control which will reside inside it. it's pretty horrific.

A nice intro article to this whole ToolWindow horror [can be read here](http://www.codeproject.com/dotnet/msgaddin.asp).

The question remains - how do you get an ActiveX control that will host your .Net user control inside it?

Luckily for us developers - this dark corner of the universe has been exposed: there is a ATL C++ implementation of just such an ActiveX control. [You can get it here](http://www.microsoft.com/downloads/details.aspx?familyid=3ff9c915-30e5-430e-95b3-621dccd25150&displaylang=en) , look for “ToolWindow Add-ins“ down in the page (and here's a [direct download](http://download.microsoft.com/download/7/f/0/7f035772-9add-4caa-ba54-979385904b40/ToolWindow.exe) link).

once you get past this hurdle - you can actually write wonderful(ugly, long) code.

So, the least I could do is refactor that bit of code you need to write into some form of generic Class with a static method.

\---------------------

Here's the code for a simple VB.Net class that takes some of the pain out of this process:

Public Class ControlHoster

    Public Shared Function SetupToolWindow(ByVal applicationObject As EnvDTE.DTE, \_

                                            ByVal addInInstance As EnvDTE.AddIn, \_

                                            ByVal caption As String, \_

                                            ByVal HostedControlFullName As String)

        Dim GUIDString As String = Guid.NewGuid().ToString()

        Dim ProgID As String = "VSUserControlHost.VSUserControlHostCtl"

        Dim assemblyLocation As String = System.Reflection.Assembly.GetExecutingAssembly().Location

        Dim objTemp As Object = Nothing

        Dim retVal As EnvDTE.Window = \_

                applicationObject.Windows.CreateToolWindow(addInInstance, \_

                                                            ProgID, \_

                                                            caption, \_

                                                            GUIDString, \_

                                                            objTemp)

        retVal.Visible = True

        objTemp.HostUserControl(assemblyLocation, HostedControlFullName)

        Return retVal

    End Function

End Class       

I really like doing this in VB.Net - makes all the casting and Reflection goo work seamlessly.

Anyway - I'm still not happy about this. I'm now facing  a more difficult problem - my Add-in does not even show up in the “Tool“ menu. I bet it's something really silly, isn't it?

## More in .Net Original

[All posts in .Net Original](https://osherove.com/blog/category/net-original)

- Jun 16, 2004

    ### [Problem & Solution: Allow only one instance of any MDI child form in your MDI application](https://osherove.com/blog/2004/6/16/problem-amp-solution-allow-only-one-instance-of-any-mdi-chil.html)

- Jun 13, 2004

    ### [Unit Testing in Whidbey - some pointers for improvement](https://osherove.com/blog/2004/6/13/unit-testing-in-whidbey-some-pointers-for-improvement.html)

- Jun 7, 2004

    ### [\[Problem and solution\] Right-to-left menus get scrambled when form is maximized](https://osherove.com/blog/2004/6/7/problem-and-solution-right-to-left-menus-get-scrambled-when.html)

- Jun 7, 2004

    ### [Israeli Blogger Dinner postponed](https://osherove.com/blog/2004/6/7/israeli-blogger-dinner-postponed.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
