Search code examples
visual-studio-2008windows-installersetup-projectrevit

How to create Revit add-in Windows installer in Visual Studio 2008


Process of manually installing a Revit 2011 add-in:

  1. Put add-in DLLs in desired location, for example C:Program Files\RevitAddin\RvtAddin.dll
  2. Create .addin xml file that contains information about add-in (location, full class name, etc.). This ".addin" file must be placed in one of the following locations:
    • For Windows 7: C:\ProgramData\Autodesk\Revit\Addins\2011\
    • For Windows XP: C:\Documents and Settings\All Users\Application Data\Autodesk\Revit\Addins\2011\

I can easily accomplish the first step with a Visual Studio 2008 Setup Project. For second step, I probably need to use Custom Action that would create xml .addin file. I don't know how to pass information(output location) from an installer to Custom Action.


Solution

  • Open up the custom actions editor where you will see folders for each phase of installation or uninstallation (Install, Commit, Rollback, Uninstall). Under each folder you will add references to your custom actions.

    Select one of these custom actions and look at the properties. There will be a property called CustomActionData which is where you map values from the installer to the custom action.

    An example of the format of this property is shown below.

    /installLocation="[ProgramFilesFolder][ProductName]" /setting1="[SETTING1]"

    Then inside your custom action class you can write the following to access this values

    string path = this.Context.Parameters["installLocation"];
    string setting1 = this.Context.Parameters["setting1"];
    

    Also you shouldn't be referencing an absolute path when writing the Revit addin file. Instead you can do the following to find the AppData folder regardless of what OS is being used.

    private string AddInManifestPath()
    {
        string appdata = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData);
        string path = System.IO.Path.Combine(appdata, @"Autodesk\REVIT\Addins\2011\DVAMC.addin");
        return path;
    }