Part One - A simple C# app to modify an ISM
As part of my nAnt build process, I discovered I needed to modify a setting in my installer at build time.
Note: I use the standalone version of the automation interface because it doesn't require having the full IDE installed on the box. The 'normal' automation interface can be used to perform the same tasks, but it will only exist on a machine with the full IDE installed. I'm assuming in these instructions that you have the standalone engine installed on your box.
In the past, I would have written a quick VB script to perform this task. But it's a new modern world

and I'm trying to mend my ways so I took off down the path of trying to write a C# task to do this, then I'm going to call this task from my nAnt build script.
Here's what I learned:
I started by using the Visual Studio IDE to create a C# console application. I wrote the code in there and got it to where it compiled and ran. Then I moved on to porting the code over into nAnt. You should be able to make a simple C# app like this in about 15 minutes.
1. Start the project. Open the IDE (I'm using Visual Studio 2005 Professional Team Edition). File > New > Project. Find Visual C# in the list. Choose Windows > Console Application. Fill in the desired project name and OK.
2. Make the project aware of the Standalone Automation Interface. Project > Add Reference.... Select the COM tab. Scroll down to InstallShield 12.0 Standalone Automation Interface. Click OK. Notice that in the Solution Explorer you now have about 10 different references listed. (This list will be important later when we need to repro these references in the nAnt script.)
3. Import the namespace reference for ease of use. At the top of the code file (program.cs) add a new using statement. This statement makes the project aware of the namespace so that as we use objects within the SAAuto12 namespace we don't have to keep prefixing them with "SAAuto12." every time. It's just a convenience thing.
using SAAuto12;
4. Open the ISM project. Declare a variable to hold the project object, then open it. Provide the full path to the ISM file you want to test this on.
ISWiProject project = new ISWiProject();
project.OpenProject(@"C:\projects\myISM.ism",false);
Note: Because my path string has slashes in it I preceded the string with the @ symbol so that the compiler won't think they are escape symbols. Also, there is no error handling in this yet, so if it can't open the file or if it opens it but it is not writable, too bad.
5. For now, save and close project. Just to get something working quickly...
project.SaveProject();
project.CloseProject();
6. Build the solution and test it. Build the solution and make sure this compiles. Go out to the command prompt and run the executable. It should run without error.
WHEE!! We now have a simple C# app that is capable of using the InstallShield automation interface to modify an ISM. Now all you have to do is add some error handling and put the code to actually make the changes between OpenProject and CloseProject. I'll blog on an example of this later.
Next blog I'll cover how to take this basic code and put it into an nAnt script.