Search code examples
c#automationcomreleaseinstallshield

Installshield Automation Interface - Always Overwrite


I am trying to automate the creation of install packages for the company i work for and am using the Installshield Automation Interface to create an MSI project. One of the things we have done up to now (manually if you can believe it) is go through all of the files we want to release after importing them into installshield and setting them to "Always overwrite" on a folder by folder basis since it seems you cant do it recursively on a parent folder. When creating a Basic MSI on the installshield GUI it lets you do this, however when creating an MSI via the COM object it appears this option is only available to InstallScript which i cant make an MSI with.

Anywho my code kinda looks like this

static void AddFiles(string[] aFiles, ISWiAuto24.ISWiProject oISProj, string sProjName, string ePackName) 
    {
        oISProj.OpenProject(sProjName, false);
        string installdirectory = "[ProgramFilesFolder]" + ePackName;
        oISProj.INSTALLDIR = installdirectory;
        Console.WriteLine("Adding ePack files");
        for (int i = 0; i < aFiles.Length;i++ )
            {
            Console.WriteLine(aFiles[i]);
            ISWiComponent NewComponent = oISProj.AddComponent("Component_"+i);
            string string_PathToFile = aFiles[i].Substring(0,aFiles[i].LastIndexOf("\\"));
            string string_RelativeToInstallDir = string_PathToFile.Substring(aFiles[i].LastIndexOf(ePackName) + ePackName.Length);
            NewComponent.Destination = installdirectory+string_RelativeToInstallDir ;
            NewComponent.AddFile(aFiles[i]);
            /*----------------------------Fails Here--------------------------------------*/
            NewComponent.OverwriteMainOptions=0;
            /*----------------------------------------------------------------------------*/
        }
        oISProj.SaveProject();
        oISProj.CloseProject();
        Console.WriteLine("Done");
    }
static voidMain(string[] args){
    ISWiAuto24.ISWiProject oISProj = new ISWiAuto24.ISWiProject();
    string ePackName = "ThisMonthsBundle"
    string[] aFiles = new[] {@"c:/Foo/Roo/Goo/"+ePackName+"/File0",@"c:/Foo/Roo/Goo/"+ePackName+"/File1",@"c:/Foo/Roo/Goo/"+ePackName+"/File2",@"c:/Foo/Roo/Goo/File3"}
    string sProjName = "C:/Foo/Bar.ism"
    oISProj.CreateProject(sProjName, ISWiProjectType.eptMsi);
    AddFiles(aFiles,oISProj,sProjName);
}

does anyone know a way around this?

the error is: COM Exception was unhandled - This property is not supported for Basic MSI Project. You need to remove the line that calls the property from your automation code.


Solution

  • I found an old forum post back in 2010 on the flexera community forum where a flexera developer responded to a user saying that this can be done like so:

    ISWiComponent NewComponent = oISProj.AddComponent("Component_1");
    NewComponent.Destination = "[ProgramFilesFolder]" + "ProgramName";
    NewComponent.AddFile("c:\File1");
    ISWiFiles Files = NewComponent.ISWiFiles;
    foreach (ISWiFile File in Files)
    {
        File.OverrideSystemVersion = true;
        File.Version = "65535.0.0.0";
    }
    

    the developer in question recognised the need for the automation interface to support the ISWiFile.AlwaysOverwrite property and raised a work order for it. i guess they just havent gotten around to it in the 8 years since

    https://community.flexerasoftware.com/showthread.php?194448-installshield-2009-automation-File-property-quot-Always-overwrite-quot

    Anyway, The above appears to work