I previously asked: Add dll reference to visual studio macros
the idea of creating the macros in my language (C#) makes it easier to create the macros. The prob
Finally here is the solution:
On the following steps I will describe how it will be possible to debug the dll that will be executed by a macro.
(Note I am debuging a macro on c# on visual studio!!!)
Create a new Solution in visual studio
Now add a new class library Project to that solution. (This is the class that will execute the macros)
Add the references EnvDTE, EbvDTE100, EnvDTE80, EnvDTE90, EnvDTE90a. Basically the same references that visual studio macros have:
Create a method that will execute the macro you plan to use on the class library.
namespace ClassLibrary1
{
public static class Class1
{
public static void Macro1(EnvDTE80.DTE2 DTE)
{
// make sure an active text document is open before calling this method
DTE.ActiveDocument.Selection.Insert("Hello World!!!");
}
}
}
Add another project (Visual Studio Add-in)
Follow the wizzard leave the defaults except on page 4 select:
Continue selecting the default options on the wizard until the project is created:
Set that project as the startup project so that when we press f5 the addin runs.
Add a reference from MyAddin1 to the class library
Once we have that reference we should be able to execute the macro from the addin. In order to do so open Connect.cs
and navigate to the method Exec
add ClassLibrary1.Class1.Macro1(_applicationObject);
so it looks like:
Add a break point at the start of the Exec method so we can debug it.
Execute MyAddin1 by pressing F5
. A new instance of visual studio should open.
On the new instance of visual studio open any solution. In this case I am opening the same solution again>
Got to tools then click on MyAddin1 but make sure a document is open:
Once you click on my addin you should hit the breakpoint!
ClassLibrary1.Class1.Macro1(_applicationObject);
So I comment out that line and on that line I placed:
var textDoc = (TextDocument)(_applicationObject.ActiveDocument.Object(string.Empty));
textDoc.Selection.Insert("Hello world");
finally when I click on MyAddin1 located on tools Hello world will be inserted!
Once I know the macro is running fine I could export the class to a class library and have the macro call the method on the dll instead of the plug in.