cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
sbrown
Level 6

Automation example in C#

We use MS TFS to build our c# solutions. These solutions include our Installshield projects. I need to set a property in the Installshield project before the solution build. I would do this in a custom task except that all the ISWIAutomation examples seem to be in VB. We are almost completly c#.

My atempt has errors:

{
ISWiAuto12.ISWiProject pProject = new ISWiAuto12.ISWiProject();
pProject.OpenProject("C:\\temp\\iswiproperty\\testproperty1\\TestProperty1\\TestProperty1.ism", false);

ISWiAuto12.ISWiProperty pProperty = new ISWiAuto12.ISWiProperty();
pProperty = pProject.ISWIProperties["MYVERSION"];

pProperty.set_Value("3.3.1.456.0");

pProject.SaveProject();
}

Any ideas?
Labels (1)
0 Kudos
(9) Replies
RobertDickau
Flexera Alumni

As a sanity check, if you're using InstallShield 2008, perhaps use ISWiAuto14 instead of ISWiAuto12?
0 Kudos
sbrown
Level 6

Actually I'm using both, but this project is a IS12 project.
0 Kudos
thepeter
Level 7

I am also changing/setting some properties before compiling my project through MsBuild. I am using the FileUpdate RegEx task within MsBuild Community Tasks
Just as an example you can have a custom Target that you call before compiling:












It is essential that you specify the Encodig Property to "us-ascii". Let me know if you need more help.
Peter.
0 Kudos
RobertDickau
Flexera Alumni

(And as for Automation, what error do you see?)
0 Kudos
sbrown
Level 6

My references list: isappserviceslib, ismautolib, ismmupdaterlib, isupgradelib, isqiauto12, iswibuildlib.

Code:
class Program
{
static void Main(string[] args)
{

ISWiAuto12.ISWiProject pProject = new ISWiAuto12.ISWiProject();
pProject.OpenProject("C:\\temp\\iswiproperty\\testproperty1\\TestProperty1\\TestProperty1.ism", false);
ISWiAuto12.ISWiProperty pProperty = new ISWiAuto12.ISWiProperty();
pProperty = pProject.ISWIProperties["MYVERSION"];
pProperty.set_Value(ref "3.3.1.456.0");
pProject.SaveProject();
}
}

Errors;
Error 1 The type 'ISWiAuto12.ISWiPropertyClass' has no constructors defined C:\temp\iswiproperty\iswiproperty\iswiproperty\Program.cs 15 49 iswiproperty

Error 2 A ref or out argument must be an assignable variable C:\temp\iswiproperty\iswiproperty\iswiproperty\Program.cs 18 37 iswiproperty
Error 3 The best overloaded method match for 'ISWiAuto12._ISWiProperty.set_Value(ref string)' has some invalid arguments C:\temp\iswiproperty\iswiproperty\iswiproperty\Program.cs 18 13 iswiproperty
Error 4 Argument '1' must be passed with the 'ref' keyword C:\temp\iswiproperty\iswiproperty\iswiproperty\Program.cs 18 37 iswiproperty
0 Kudos
RobertDickau
Flexera Alumni

This seems to work as a hasty mock-up in InstallShield 2009 (assuming the property MYVERSION already exists in the Property table):[code]using System;
using System.Collections.Generic;
using System.Text;

namespace ISWiAuto15CS
{
class Program
{
static void Main(string[] args)
{
ISWiAuto15.ISWiProject ism = new ISWiAuto15.ISWiProject( );
ism.OpenProject(@"C:\InstallShield 2009 Projects\BasicMsi2009.ism",
false);

ISWiAuto15.ISWiProperty pProperty = ism.ISWiProperties["MYVERSION"];
String myVersion = "3.3.1.456.0";
pProperty.set_Value(ref myVersion);

ism.SaveProject( );
ism.CloseProject( );
}
}
}[/code]
0 Kudos
sbrown
Level 6

That works in IS 12 also.

Thanks

Since I have IS 12 and IS2008 on the same machine I think I'm going to try the regex first.
0 Kudos
profil92
Level 3

L'exception System.IndexOutOfRangeException n'a pas été gérée
HelpLink="#1000005"
Message="Item not found\r\n > ISWiAutomation.ISWiProperties.Item"
Source="ISWiAuto12"
StackTrace:
à ISWiAuto12.ISWIPropertiesClass.get_Item(Object vntIndexKey)
à GenProduct.Program.Main(String[] args) dans C:\Documents and Settings\jerome\Bureau\GenProduct\Program.cs:ligne 176
à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
0 Kudos
profil92
Level 3

profil92 wrote:
L'exception System.IndexOutOfRangeException n'a pas été gérée
HelpLink="#1000005"
Message="Item not found\r\n > ISWiAutomation.ISWiProperties.Item"
Source="ISWiAuto12"
StackTrace:
à ISWiAuto12.ISWIPropertiesClass.get_Item(Object vntIndexKey)
à GenProduct.Program.Main(String[] args) dans C:\Documents and Settings\jerome\Bureau\GenProduct\Program.cs:ligne 176
à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()


RobertDickau wrote:
This seems to work as a hasty mock-up in InstallShield 2009 (assuming the property MYVERSION already exists in the Property table):[code]using System;
using System.Collections.Generic;
using System.Text;

namespace ISWiAuto15CS
{
class Program
{
static void Main(string[] args)
{
ISWiAuto15.ISWiProject ism = new ISWiAuto15.ISWiProject( );
ism.OpenProject(@"C:\InstallShield 2009 Projects\BasicMsi2009.ism",
false);

ISWiAuto15.ISWiProperty pProperty = ism.ISWiProperties["MYVERSION"];
String myVersion = "3.3.1.456.0";
pProperty.set_Value(ref myVersion);

ism.SaveProject( );
ism.CloseProject( );
}
}
}[/code]



[FONT="Tahoma"]
i've an execption, but why ? if you have a solution for me it's excellent because the CHM Help in installshield 12 premier isn't a good reference for help me.
in fact i would like to realise a C# program who automatise some opperation
like copy files and folders, generate a build/release with installshield automation, i've create before the setup type and version of product manually.
in my program for installshield, i used the name of product already created the exit for this part is générate the new setup.exe whith the same installscript but the new installfiles.


detail of the error message :

L'exception System.IndexOutOfRangeException n'a pas été gérée
HelpLink="#1000005"
Message="Item not found\r\n > ISWiAutomation.ISWiProperties.Item"
Source="ISWiAuto12"
StackTrace:
à ISWiAuto12.ISWIPropertiesClass.get_Item(Object vntIndexKey)
à GenProduct.Program.Main(String[] args) dans C:\Documents and Settings\jerome\Bureau\GenProduct\Program.cs:ligne 176
à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()[/FONT]
0 Kudos