Tutorial: Deploy your Enterprise Architect # add-in with an MSI package

Tutorial: Deploy your Enterprise Architect C# Add-in with an MSI package

by Geert Bellekens [email protected]

originally published on http://geertbellekens.wordpress.com at http://wp.me/p1dEib-3j

2011-02-23 Author: Geert Bellekens Page 1 of 12

Tutorial: Deploy your Enterprise Architect C# add-in with an MSI package

Contents

Requirements...... 3

The plan ...... 3

Step 1: Create a setup project ...... 4

Step 2: Edit Setup.wxs...... 6

Step 3: Add the program files ...... 7

Step 4: Register MyAddin.dll for COM Interop...... 8

Step 5: Add the EA Addin registry key...... 9

Step 6: Fill in the license details...... 11

Step 7: Build and test your setup project ...... 11

More resources ...... 12

Related blog posts...... 12

Source code on GitHub ...... 12

Sparx Systems ...... 12

Other...... 12

2011-02-23 Author: Geert Bellekens Page 2 of 12

Tutorial: Deploy your Enterprise Architect C# add-in with an MSI package

In previous posts I talked about Creating and Testing your Enterprise Architect C# add-in, and how to use the C# add-in template to speed up the development process.

Once created and tested you’ll probably want to install and use the add-in on other computers then your development machine. This tutorial explains how to create an MSI installer package using the SharpDevelop and WiX software.

The reason I’m using SharpDevelop as opposed to Visual Studio C# Express is because SharpDevelop is free and open source, and Visual Studio C# Express doesn’t allow to create setup projects, or attach to a running process to debug your add-in. Requirements • SharpDevelop 4.0 http://www.sharpdevelop.net/OpenSource/SD/Download/#SharpDevelop4x

• WiX 3.5 http://wix.codeplex.com/releases/view/60102

SharpDevelop 4.0 already contains Wix 3.0, but we need 3.5 for the “register for COM interop” functionality. SharpDevelop 4.1 comes with Wix 3.5, but at the moment of writing that is still in pre-alpha phase, and not stable enough to be used. The plan As explained in Tutorial: Create your first C# Enterprise Architect addin in 10 minutes we need our installer to do three things for us:

• Copy the dll’s to a program folder.

• Register the add-in dll for COM Interop so Windows knows where to find the add-in dll.

• Create the registry key so EA knows about our add-in.

2011-02-23 Author: Geert Bellekens Page 3 of 12

Tutorial: Deploy your Enterprise Architect C# add-in with an MSI package

Step 1: Create a setup project • Open the solution for your add-in in SharpDevelop. If you have developed the add-in with Visual Studio, that fine. Sharpdevelop uses the exact same project setup as Visual Studio, with the .sln and .csproj files

• Add a new project and choose for Setup Project – WixUI Minimal You can of course choose for another template, but for the purpose of this tutorial the WixUI Minimal is enough.

2011-02-23 Author: Geert Bellekens Page 4 of 12

Tutorial: Deploy your Enterprise Architect C# add-in with an MSI package

• SharpDevelop will now have created a new Setup project in your solution containing three files:

o Files.wxs This is were we define wich files and registry keys the installer needs to install

o license.rtf Contains the license for your software

o Setup.wxs Where we define the general setup of the installer like the name, and the components to install.

2011-02-23 Author: Geert Bellekens Page 5 of 12

Tutorial: Deploy your Enterprise Architect C# add-in with an MSI package

Step 2: Edit Setup.wxs Next we’re going to tell the installer about the application it will install. The .wxs files are actually XML files, and you can edit them directly in SharpDevelop.

• Open Setup.wxs and edit the highlighted parts

Notice that we also added a ComponentRef for MyAddinRegEntries.

2011-02-23 Author: Geert Bellekens Page 6 of 12

Tutorial: Deploy your Enterprise Architect C# add-in with an MSI package

Step 3: Add the program files • Open up the setup files view with View|Setup|Files

• Right-click on the MyAddinFiles component and choose Add Files…

Now browse to the MyAddin project folder and select all files in the MyAddin\bin\debug or MyAddin\bin\release folder, depending on how you last built your project. Not all of these files might be necessary, but I can’t be bothered to figure out exactly which files we need to install the add-in on another computer.

• This should now have created a line in the files.wxs for each binary file similar to

2011-02-23 Author: Geert Bellekens Page 7 of 12

Tutorial: Deploy your Enterprise Architect C# add-in with an MSI package

Step 4: Register MyAddin.dll for COM Interop The MyAddin.dll is the add-in dll that EA needs to talk to, so this dll needs to be registered for COM Interop. This is the part that is done by regasm.exe when doing a manual installation, but we don’t want to be calling any executables on the target machine during install if we can avoid it. Instead we will just add the same registry keys that regasm.exe creates.

This is the part were we need WiX version 3.5, because the previous versions don’t take into account the COM Interop stuff.

• Open a command prompt in the folder where MyAddin.dll is located (bin\Debug\)

• Execute following command: "C:\Program Files\ XML v3.5\bin\heat.exe" file MyAddin.dll -ag - template fragment -out MyAddin.wxs This will have created a file in the same folder with the name MyAddin.wxs.

• Open that file and copy the contents of the Component tag:

• Replace the file tag for MyAddin.dll in your files.wxs by the copied part

2011-02-23 Author: Geert Bellekens Page 8 of 12

Tutorial: Deploy your Enterprise Architect C# add-in with an MSI package

• Add a Name attribute Name=”MyAddin.dll to the file tag for MyAddin.dll so the tag looks like: Step 5: Add the EA Addin registry key This step will instruct the installer to create the add-in registry key that tells EA there is an add-in to load

• Add following Registry key tag to the MyAddinRegEntries tag in the Files.wxs

All file editing should now be behind us. The complete Files.wxs should look something like:

2011-02-23 Author: Geert Bellekens Page 10 of 12

Tutorial: Deploy your Enterprise Architect C# add-in with an MSI package

Step 6: Fill in the license details • Open license.rft in wordpad, or another rtf editor and fill in the license details Do NOT use Word to edit the license.rtf as Word will make a horrible mess of the rtf file. Step 7: Build and test your setup project Now all we need to do is build and test the setup project. You can run it right from within Sharpdevelop.

If all is well you should see something similar to this:

2011-02-23 Author: Geert Bellekens Page 11 of 12

Tutorial: Deploy your Enterprise Architect C# add-in with an MSI package

More resources

Related blog posts • http://geertbellekens.wordpress.com/2011/02/23/2011/01/29/tutorial-create-your-first-c- enterprise-architect-addin-in-10-minutes/

• http://geertbellekens.wordpress.com/2011/02/08/testing-and-debugging-your-enterprise- architect-csharp-add-in/

• http://geertbellekens.wordpress.com/2011/02/16/the-complete-enterprise-architect- csharp-add-in-template/ Source code on GitHub • http://geertbellekens.github.com/Enterprise-Architect-Add-in-Framework/

• http://geertbellekens.github.com/UML-Tooling-Framework/

• http://geertbellekens.github.com/Enterprise-Architect-Toolpack/ Sparx Systems • http://www.sparxsystems.com/enterprise_architect_user_guide/8.0/automation_and_scrip ts/automation_interface.html

• http://community.sparxsystems.com/

• http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?board=Automation Other • http://themodelfactory.org/Modelling_Tooling

• http://themodelfactory.org/Pattern:Modelling_Tooling_Framework

• Examples in the EA installation folder: C:\Program Files\Sparx Systems\EA\Code Samples

2011-02-23 Author: Geert Bellekens Page 12 of 12