Monday, August 22, 2011

[Revit API]–How to create an installer for your Revit Addins

Often I see Revit API utilities distributed with instructions to copy manifest files around and put the files in a certain directory (I’ve done it myself in the past), which works fine, but there is a more user friendly way of setting up your addins. You can use Visual Studios ‘Setup Project’ functions to create an installer, which isn’t the pretties installer going around, but it gets the job done.
Doing this is a little harder than you’d think, there’s a few gotchas, so this post aims to step you through it.
Add a new project to your solution, under ‘Other Project Types’, ‘Setup and Deployment’ choose ‘Setup Project’.
You’ll see a view like this, delete ‘Users Desktop’, ‘User Programs Menu’
Right click on Application folder and go to add > project output. Choose the Addin project.
Right click on application folder again, go to properties and change the DefaultLocation to be:
This is so that it will always be in a consistent install location, rather than program files (x86).
Now, we don’t want to distribute RevitAPI and RevitAPIUI dlls, so in the solution explorer, expand detected dependencies and right click on those and click exclude.
Click on the installer project, then click the properties tab, and set the ‘Manufacturer’ and ‘ProductName’ to match your company/addin name. Also, while you are here, change the ‘TargetPlatform’ to X64. Unfortunately with these types of installers you need a separate install for X86 and X64, but I think most of you will be building API addins for X64 systems, as Revit generally needs at least 4gb of RAM, and if you are enough of a power user to be installing add-ins, you are going to be running a 64bit operating system I’m sure. But keep in mind that it may vary for you.
We need to create a .addin manifest file that points to the program files folder as follows, make sure you generate a new GUID.
  <AddIn Type="Command">
    <Text>My Revit Util</Text>
    <Assembly>C:\Program Files\COMPANY NAME\PRODUCT NAME\Addin.dll</Assembly>
  <VendorId>COMP </VendorId>
     <VendorDescription>MY COMPANY </VendorDescription>  

In The primary output screen, add a new custom folder, called Autodesk Addins. Right click on it and go to properties and set the DefaultLocation to
and Property to AUTODESKADDINS
This will install it for all users. Right click in the middle panel and go to add file, and choose your manifest.
At this point you’re almost done, there’s just a couple of .NET settings to tweak. First of all, we don’t need to bundle an installer for .NET framework as Revit installs it by default, so right click on your installer project, go to properties and hit prerequisites
Then untick the first checkbox
Finally, right click on your project, click View > Launch Conditions, click .NET framework and change it to .NET Framework 4 (or lower if you are in Revit 2011 mode still).
Now you are done, you can right click your project and go to Build and your .msi installer will be output.

1 comment:

Marchart said...

Take a look at WiX Toolset to create Windows installation. It's open source.