---
title: "VS Addins Revisited: Declarative button order and location with a DSL"
url: "https://osherove.com/blog/2008/8/3/vs-addins-revisited-declarative-button-order-and-location-wi.md"
canonical: "https://osherove.com/blog/2008/8/3/vs-addins-revisited-declarative-button-order-and-location-wi.html"
published: "2008-08-03T16:05:31"
updated: "2008-08-03T16:05:31"
tags: [".NET", ".Net 2.0", "Extensibility"]
author: "Roy Osherove"
description: "First, here is the code with the updates . In the previous post I showed how you can declaratively create buttons with captions and icons in a visual studio addin. the next problem to solve in that space is how to you…"
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/"
---

# VS Addins Revisited: Declarative button order and location with a DSL

By Roy Osherove August 3, 2008 In [.NET](https://osherove.com/blog/category/net), [.Net 2.0](https://osherove.com/blog/category/net-2-0), [Extensibility](https://osherove.com/blog/category/extensibility)

**Historical article** · Originally published August 3, 2008; technical details may be outdated.

First, [here is the code with the updates](http://files.osherove.com/downloads/DeclarativeLocationBasedAddinButtons.zip).

In the [previous post](http://weblogs.asp.net/rosherove/archive/2008/08/02/declarative-visual-studio-addin-buttons-with-icons.aspx) I showed how you can declaratively create buttons with captions and icons in a visual studio addin. the next problem to solve in that space is how to you order them the way you want relative to each other?

A way I’ve come up with has a code based DSL that allows you to declare the location of each button type you have create like this:

 public static ButtonLocationConfigurator LoadButtonConfiguration()

        {

            ButtonLocationConfigurator configurator \= new ButtonLocationConfigurator();

            configurator

                    .UnderCommandBar("MenuBar")

                               .UnderMenu("Test")

                                 .PlaceButton<HelloWorldAddinAction\>(ButtonVisuals.StartsNewGroup)

                                 .PlaceButton<ActionThatReplacesItsIcon\>();

            return configurator;

        }

The buttons should be placed correctly under the main menu bar under the test menu with the “HelloWorld” action above the other one.

Here is part of the code that makes this possible. first, what does the connect.cs look like?

public void OnConnection(object application, ext\_ConnectMode connectMode, object addInInst, ref Array custom)

        {

            \_applicationObject \= (DTE2)application;

            \_addInInstance \= (AddIn)addInInst;

            if(connectMode \== ext\_ConnectMode.ext\_cm\_UISetup)

            {

                CommandBars bars \= (CommandBars)\_applicationObject.CommandBars;

                Commands2 commands \= (Commands2)\_applicationObject.Commands;

                AddinCreatorContext creatorContext \=

                                       new AddinCreatorContext(\_applicationObject, \_addInInstance, commands, bars);

                AddinRegistry.LoadButtonsByConfiguration(creatorContext);

            }

        }

This works really nicely and you can grab that code the [does it here](http://files.osherove.com/downloads/DeclarativeLocationBasedAddinButtons.zip).

## More in .NET

[All posts in .NET](https://osherove.com/blog/category/net)

- Aug 12, 2008

    ### [Build and Continuous Integration - Toolgasm achieved](https://osherove.com/blog/2008/8/12/build-and-continuous-integration-toolgasm-achieved.html)

- Aug 12, 2008

    ### [ALT.NET Israel Wrap up](https://osherove.com/blog/2008/8/12/altnet-israel-wrap-up.html)

- Aug 3, 2008

    ### [Before testing an addin - Reset Visual Studio’s previous addin knowledge](https://osherove.com/blog/2008/8/3/before-testing-an-addin-reset-visual-studios-previous-addin.html)

- Aug 2, 2008

    ### [Declarative Visual Studio addin buttons with icons](https://osherove.com/blog/2008/8/2/declarative-visual-studio-addin-buttons-with-icons.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/
