Deploying Applications with the InteropForms 2.0 toolkit

(Recently, we released the InteropForms 2.0 toolkit which allows you to add the richness of .net windows forms to your vb6 application.  We’ve gotten a fair number of questions from customers asking for more details on deployment, so this will hopefully answer most of your questions)
As I’m sure you’re aware, deploying VB6 COM based applications can get complicated at times, which is one of the great advantages that moving your applications to .NET gives you.   The Interop Forms Toolkit 2.0 allows you to easily extend your VB6 applications with .NET functionality, which is great, but it creates some interesting deployment issues.   The good news is that there are some things we did in the latest 2.0 release to make this much easier than before and we tried to document the different strategies, but given that there are plenty of ways to do things, we wanted to blog about this in more detail.
To save you some time, here’s what we recommend in general with building mixed apps.
a)  Use the Interop Forms Toolkit to build Interop Usercontrols instead of Interop Forms.
b)  Remove the reference to Microsoft.InteropForms.dll library unless you plan on taking advantage of some of it’s functionality such as the Globals class (for sharing state) or the EventMessenger class (for raising application-level events).
c)  Configure your usercontrol manifest appropriately and create an application manifest for your VB6 app so you can take advantage of Reg-free COM
d)  Modify your legacy setup to copy over your new usercontrol binary and the application manifest into your application folder.
If you can do this, you can easily augment an existing application in a painless way.  Deploying an application created this way is as simple as copying the new files down into the target directory.  Of course, this doesn’t work for all situations and I’ve glossed over a few other details that should be mentioned.   To decide on the best way to deploy your application, you have to deal with three issues.  
1) Prerequisites:
If you use an Interop usercontrol/form in your project, your clients need to have the .NET framework 2.0 installed on their system.   This framework is on machines by default in Vista and may be on your client machines anyway, but if not, here’s some options.   (This assumes you have permissions to install/rollout .msi setups that globally effect the machine.)
1) The recommended approach is to use the bootstrapper technology in VS 2005 to deploy any prereqs you need.   You can create a custom bootstrapper which installs prereqs like the .net framework only if necessary and in a secure way.   These prereqs that the bootstrapper supports are typically called “bootstrapper packages” and you can see what’s available on your machine by going to the Publish tab in the project designer and clicking on “Prerequisites” button.
A “custom bootstrapper” is basically a special “setup.exe” that is built by VS that understands what prereqs are needed for your application.   Once the prereqs are installed, it will launch whatever you want – typically the application setup.   If you ever build a Setup and Deployment project in VS or publish a Clickonce app, the “setup.exe” that is created is a custom bootstrapper.
2) Alternatively, you can roll your own approach (use batch file, etc…) which I won’t go into detail here.
For most .Net created apps, the .Net 2.0 framework is the only dependency you have.   However if you use InteropForms (rather than Interop Usercontrols) you take an a dependency on a binary called the “Microsoft.InteropFormTools.dll”.   You also have this dependency by default if you create an Interop UserControl project, although you can safely remove it unless you explicity want to use some of the objects in this assembly.    We have bundled this file in a redist package and created a bootstrapper package so you can safely and securely deploy this binary just like you would with the .Net framework.
Lastly, if your Interop project has any extra 3rd party dependencies, you’ll need to ensure those are appropriately installed.   If you want, you can create your own bootstrapper package for them and have the VS bootstrapper take care of installing them for you.
Creating a custom bootstrapper:  Check out the “How To: Deploy a Hybrid Application” topic in the Interop Forms Toolkit documentation.   
Creating a bootstrapper package:   Check out these links:
Actually, there’s a great tool that David Guyer created to allow you to visually create both a custom bootstrapper or a bootstrapper package.   I highly recommend it.   You can download it (via ClickOnce!) here:
2) Registering the Controls with Reg-Free COM:
Registration free COM is a cool technology that works in Windows XP and later operating systems that allows you to deploy COM-based binaries without having to register them.  If you can be sure that your clients will be on this platform or later, then it can make your deployment story much easier if you use Interop UserControls.   As I mentioned above, the only thing you need to add to legacy application is add your new usercontrol assembly and an application manifest file to your application and copy those files to the application directory and you’re done.
If you use InteropForms projects (or say you have to support older platforms like Windows 98 or Windows 2000), this approach won’t work and you’ll need to use regasm (or a windows .msi) to deploy your assemblies which is more difficult, but still quite doable.   If you use InteropForms projects, probably the easiest way to deploy them is in this manner:
1) Create a VS Setup and Deployment project and add your InteropForms assembly to it.   Also, make sure you set the register property to vsdraCOM so that will get globally registered on the machine and build your .msi
2) Create a bootstrapper package for this .msi and then add this package to your custom bootstrapper.
Interop UserControls projects cannot be deployed this way b/c they rely on some additional code to get run to register them properly (check out the code in the method with the DllRegisterFunction() attribute), so you need to use regasm.exe directly if you want to deploy them and cannot use reg-free COM.
Note:  If you do need to use regasm.exe, what I find to be the best approach is to create an .msi like above, but use a custom action to register/unregister the assembles.   The good news is that we’ve shipped the code to do this and you can just borrow what we have.   Look in the file in the installation folder and check out the “bootstrapperpackageinstaller” project for details.   In the “How to: Deploy a Hybrid Application” in the Interop Forms documentation, we also mention that you can ship regasm.exe in your installer, although I would recommend using the code that we ship (which searches for and finds the right copy of regasm.exe installed locally).
Search MSDN for “vsdraCOM” and you’ll get a bunch of information around this.   Also, check out the links mentioned above for more information on bootstrapper information.
3) Your existing setup:
Part of the choosing of the best way to deploy your application comes from what you can do with your existing setup.  Here’s the common scenarios and what we recommend.
a) Your setup is frozen (or you cannot modify it).
In this case, you can create a custom bootstrapper to install all prereqs that your application needs (whatever component you created in (2) above).   You will end up with a single setup.exe which will launch and setup everything the application needs.
b) Your setup is a windows .msi file created in VS.   In this case, you can just add the appropriate logic for installing your assembly (see (2) above) and you can just goto the Prerequisites dialog for the setup project and rebuild your .msi.   VS will create a custom bootstrapper (the setup.exe) that installs all needed prerequisites.
c) Your setup is created with the VB6 package and deployment wizard or some other technology and you can modify it.   Depending on (1) above – namely, if you need to install prerequisites, you might want to create a custom bootstrapper to “wrap” your legacy setup.   Depending on (2), you can either just add your files to your setup (if you use RegFree COM and Interop Usercontrols), or can do something custom for your setup.
Anyway, I hope that helps clear up any confusion around deploying hybrid applications.   If you run into questions/issues feel free to ask questions here and we’ll do our best to help you out.
Also we’ll be doing a webcast with demos and some Q&A on June 6th, you can register for it here:
Good luck!