Open your visual studio, new a project, New a project.

Choose the Visual C# – > Windows in the left panel, and select “Class Library” in the right panel, then input “myRevitApp” in the Name edit box, after that, click OK to new a project,Project Setting.

In the project solution tree, right click ”References”, click “Add Reference”:Add Reference.

Choose the fourth tab “Browse” tab, and browse the directory of your revit application, then choose “RevitAPI.dll” and “RevitAPIUI.dll”

Add Reference Dialog

In addition, please add reference of “System.Windows.Forms” from “.Net” tab. Then add following three lines before the namespace…

using System.Windows.Forms;
using Autodesk.Revit;
using Autodesk.Revit.UI;

And replace the text in the namespace area with following code:

   [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
   [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
   public class Class1 : IExternalCommand
   {
      public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
      {
         MessageBox.Show(“my first revit application!”);
         return Result.Succeeded;
      }
   }
Build the solution. Add an empty file named myRevitApp.addin and add following text in this file:

<?xml version=”1.0″ encoding=”utf-8″?>
<RevitAddIns>
  <AddIn Type=”Command”>
    <Assembly>C:\Project\Projects\myRevitApp\bin\Debug\myRevitApp.dll</Assembly>
    <ClientId>7cbae747-78f9-4dd5-ac92-a94f6229f9b3</ClientId>
    <FullClassName>myRevitApp.Class1</FullClassName>
    <VisibilityMode>AlwaysVisible</VisibilityMode>
  </AddIn>
</RevitAddIns>

Please change the Path in the <Assembly> to the dll you just build. And put this file in C:\ProgramData\Autodesk\Revit\Addins\2011 if you’re using win7, or C:\Documents and Settings\All Users\Application Data\Autodesk\Revit\Addins\2011\ if you’re using window xp.

And run your revit, you can see an add-ins tab, click the button under “External Tools”, you will see the pop up message box.

Add ins command   Message box

Enjoy.