Hi there, it’s me again. Back this time to cover a more Windows-Centric option: .NET Languages. In this particular case, I’m working in C# due to this being most familiar to me among the offerings.
To start with, one prerequisite is to add a reference to your project for the InstallShield Automation Library, which is located in the file ISWiAutomation##.dll
, where the ## corresponds to the version of InstallShield you’re using. For example:
C:Program FilesInstallShield2010SystemISWiAutomation16.dll
C:Program FilesInstallShield2011SystemISWiAutomation17.dll
And so on.
Once you’ve got this reference imported, there’s no CreateObject()
call like in previous examples, since the CLR will handle this on the back end.
Example 1: Listing Features and Components
This example illustrates iterating through root level features and components.
static void Main(string[] args)
{
String strOutput = “”;
ISWiAuto17.ISWiProject m_ISWiProj = new ISWiAuto17.ISWiProject();
string strFile = “C:InstallShield 2011 ProjectsMY 64 bit Project.ism”;
m_ISWiProj.OpenProject(strFile,false);
foreach (ISWiAuto17.ISWiFeature m_Feature in m_ISWiProj.ISWiFeatures)
{
strOutput += “Feature: ” + m_Feature.Name + “n”;
strOutput += “Components “;
foreach (ISWiAuto17.ISWiComponent m_Component in m_Feature.ISWiComponents)
{
strOutput += m_Component.Name + ” “;
}
strOutput += “n”;
}
Console.WriteLine(strOutput);
m_ISWiProj.CloseProject();
}
Example 2: Setting Component Properties
This example illustrates getting a specific feature from the ISWiFeatures collection, using it to set component properties, and then saving the project.
static void Main(string[] args)
{
ISWiAuto17.ISWiFeature m_Feature;
ISWiAuto17.ISWiProject m_ISWiProj = new ISWiAuto17.ISWiProject();
string strFile = “C:InstallShield 2011 ProjectsMY 64 bit Project.ism”;
m_ISWiProj.OpenProject(strFile, false);
m_Feature = m_ISWiProj.ISWiFeatures[“MyApplication”];
foreach (ISWiAuto17.ISWiComponent m_Comp in m_Feature.ISWiComponents)
{
m_Comp.RemoteInstallation = ISWiAuto17.ISWiRunFromSource.rfsSource;
}
m_ISWiProj.SaveProject();
m_ISWiProj.CloseProject();
}
Cary-
Do you have any suggestions on making that code version-neutral for when you have to support multiple baselines building against different versions of InstallShield?
(See: http://stackoverflow.com/questions/3419764/how-to-make-a-net-com-wrapper-generic )
I’ve worked out a couple hacks on my end but this is where I really wish InstallShield provided a factory to serve up the different automation interface versions.
Hi Chris,
I saw your listing of the ways you came up with to handle this; some I was aware of, and others not.
http://blog.deploymentengineering.com/2010/12/installshield-automation-interop-with.html
Indeed, I know of no other ways to make the code version-independant, as each approach ends up as being hacky, overly time consuming, not type-safe or all of the above.
I actually wrote up the samples in Java using an Interop library, and it is indeed as you describe – lots of Dispatch.Invoke(), and no type safety.
All told, my opinion of the lesser of all evils would be .Net 4.0’s Dynamic type and just have it installed on a build server.
HOw to proceed for automation using ISWiAuto20.
This scomes in Installshield 2013 version.
Inspite of registering all dlls’ and OCX of installshield, still its fails at:
ISWiAuto20.ISWiProject m_ISWiProj = new ISWiAuto20.ISWiProject();
Also I observed that, in 2013 version, ISM file is not created when new project is created using VS 2010.
Thank you for your question. You may be able to find an answer if you search the knowledge base and other online documentation at http://www.revenera.com/support.
Set The Platform target to x86. Under Properties->Build of the c# Project.
Same problem here!
Since IS2013 our .NET Solution isn’t working anymore:
Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘ISWiAuto20.ISWiProject’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{872D23A7-C18D-468C-895D-1CF027E4FBB1}’ failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))
Hello Cary,
have you any idea how to reprograming VB to c# or powershell code?
Especially I would like to know the way, how do I catch build events ( progress … ) using powershell, please.
==================================================================================
Public WithEvents pISWiRelease As ISWiAutoAutomation Interface Version.ISWiRelease
Private Sub Foo()
Dim pISWiProject As IswiAutoAutomation Interface Version.ISWiProject
Set pISWiProject = CreateObject(“IswiAutoAutomation Interface Version.ISWiProject”)
pISWiProject.OpenProject “C:\InstallShield 2016 Projects\My Project Name-1.ism”, False
Set pISWiRelease = pISWiProject.ISWiProductConfigs(“Product Configuration 1”).ISWiReleases(“Release 1”)
pISWiRelease.Build
pISWiProject.CloseProject
Set pISWiRelease = Nothing
Set pISWiProject = Nothing
End Sub
Private Sub pISWiRelease_ProgressIncrement(ByVal lIncrement As Long, pbCancel As Boolean)
‘ Place your code here
End Sub
Private Sub pISWiRelease_ProgressMax(ByVal lMax As Long, pbCancel As Boolean)
‘ Place your code here
End Sub
Private Sub pISWiRelease_StatusMessage(ByVal sMessage As String, pbCancel As Boolean)
‘ Place your code here
End Sub
Are there more examples using C# for automating installation development and build processes with InstallShield? All I can find with online help is out of date examples using VisualBasic.