Cameron Castillo
Cameron Castillo

Reputation: 2852

C#: Create custom msi file

I need to create a custom installer to deploy a specific program. But there are a few checks and balances that needs take place during intallation, and even though I have an Advanced Installer license, it just struggles to do everything I need.

I'm looking for a way to create my own msi file using c#. Running the msi file it will then start a win forms wizard, which in turn will do a number of items, including copying files to the host PC.

I'm not sure how I can "include" my set of files into a single msi file. How to you "copy" files into an msi and how can you read again from it?

I can't even give a proper sample code of what I've tried as I don't know where to start.

This just feels like it should be a duplicate question, but I can't find it.

Upvotes: 0

Views: 357

Answers (1)

Bogdan Mitrache
Bogdan Mitrache

Reputation: 11023

I work at Advanced Installer, since you said you already have a license let's help you get a return of investment on that ;)

First of all, I seriously doubt you need to reinvent the wheel and write your own code that installs/copies files on the machine. This is a basic action performed by all installer authoring tools, and even though it seems simple when you first think about it, it is not. You don't want to write code that handles rollbacks (if your install fails), reference counts (if a file is shared somehow), repair/self-healing operations (if somehow a DLL gets corrupted or missing post-install), or cover other standard Windows Installer scenarios.

Since you didn't explain with full details what you are trying to do I will give you some short example on how to do each of the steps you mentioned:

  1. Adding files in a setup package - this is a link to a tutorial created with a free edition, but the same steps apply for Professional and Enterprise editions.

  2. Searching files on a disk and retrieving values from them. - for this, you need to use the built-in support from Search page. There you can either simply search for a file and return its path or search for an element inside an INI or XML file and return its value inside a property.

Windows Installer properties are the equivalent of variables in your code. You can use them all over the installer project to pass/get/validate values.

  1. Designing custom dialogs. Most professional installer authoring tools have support to build custom dialogs. The previous link is for a tutorial on how you can do that with Advanced Installer.

During the UI stages, you can include and custom C# code to perform additional validations or data retrieval operations and pass that to or from the installer using properties. if you need it.

The custom installer dialogs support is available starting with the Enterprise edition. The Professional and Free editions include the standard dialogs, but with no options to customize them.

Another way to interact with users is to design an UI experience inside your application that is visible only when the users launch the application for the first time. So, this is not a part of your installer. It will be code that you write inside your application and you can provide a first-launch experience similar to what you see when you install Office for example. If you can give me more details on what you want to do/capture in those custom dialogs, I will try to recommend you the best approach.

Upvotes: 2

Related Questions