2

I've created very simple Visual Studio Add-in, ala this article by JP Booodhoo.

http://codebetter.com/jpboodhoo/2007/09/04/macro-to-aid-bdd-test-naming-style/

The addin works in debug, so if I F5 in the add in solution, and open a solution then the addin shows in the tools. However, it doesn't show when not debugging. i.e. after I've deployed the addin, closed and re-opened my solution.

Am I missing something?

In terms of deployment, I followed the deployment steps in this article and deployed it to C:\Users[your user name]\Documents\Visual Studio 2012\Addins

Alternative to macros in Visual Studio 2012

public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
            if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                if(commandName == "KinghamExtensions.Connect.KinghamExtensions")
                {


                    var selection = (TextSelection)(_applicationObject.ActiveDocument.Selection);
                    selection.SelectLine();
                    if (selection.Text == "") return;

                    var prefix = "public void ";
                    var index = selection.Text.IndexOf(prefix);
                    prefix = selection.Text.Substring(0, index) + prefix;
                    var description = selection.Text.Replace(prefix, String.Empty);

                    selection.Text = prefix + description.Replace(" ", "_").Replace("'", "_");
                    selection.LineDown();
                    selection.EndOfLine();
                    handled = true;
                }
            }
        }

As I say, the code works when running the addin from vs in debug, but doesn't show in the tools menu.

Also, it doesn't show up in the keyboard options like the Git Extensions addin does meaning I can't assign a key binding.

Any thoughts?

Community
  • 1
  • 1
Tim Butterfield
  • 565
  • 5
  • 24

1 Answers1

0

It is hard to answer by the information you given, but at first you should check the followings:

Your AddIn should appear in the Tools>Add-in Managger...

If you set the first check box before it, than it should be loaded.

If it isn't and you get an error message, click to no, else the Studio will rename the deployed .AddIn file. You should check if your release assembly is at the place referenced by the Assembly element like this: <Assembly>C:\Users[your user name]\Documents\Visual Studio 2012\Projects\MyAddin1\MyAddin1\bin\MyAddin1.dll</Assembly>
in the .AddIn file deployed by Visual Studio to the AddIn folder you mentioned in your question.

If it is, and the error pesrists, you should add some log to your Add-In (a Windows MessageBox will do) and place it to the OnConnection method. The error can appear either OnConnection throws an Exception while the IDE trying to load it, or the FullClassName element in the AddIn file refers to an other name than your Connection class has.

If you get no errors and your OnConnection runs properly, then it could be an exception thrown while your code is adding your command, - if you do the same way as it is in a generated Add-In template in a try/catch block- and you need to resolve it.

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Ursegor
  • 878
  • 8
  • 16