This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Automation using C# to change PathVariable
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Mar 27, 2009
01:10 PM
Automation using C# to change PathVariable
I have several projects where i need to update the PathVariable before creating my MSI. I had been doing this using vbscript but I now want to switch over to using a Custom Task in TFS Team Build.
I can't seem to get my program to work however. One problem is When i am creating my task ISWiPathVariables does not have an 'Item' member like the documentation states. I tried to work around it by looping through all objects in the ISWiPathVariables collection but I cannot create the ISWiPathVariable object. I get an error stating there is no default constructor.
Here is a trimmed down version of my code to make it easier to read. Can anyone tell me what the problem could be? I know i must just be missing something obvious.
I am using InstallShield 2009 and I have already added a reference to ISWiAutomation15.dll in my solution. I already have a task that updates the Version in the same Solution so at least something works.
[CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ISWiAuto15;
using System.IO;
namespace SetPathVariable
{
class Program
{
static void Main(string[] args)
{
bool success = false;
int ISOpenSuccess = int.MinValue;
int ISSaveSuccess = int.MinValue;
string ISMPath = @"Z:\PathToInstaller.ism";
string PathValue = @"D:\SomePath\";
string PathVariable = "PATH_TO_FILES";
string IsmName = Path.GetFileName(ISMPath);
ISWiAuto15.ISWiProject oProject = new ISWiAuto15.ISWiProject();
try
{
// Open the ISM so we can update the PathVariable
oProject.OpenProject(ISMPath, false);
ISWiAuto15.ISWiPathVariables pathVariables = new ISWiPathVariables();
pathVariables = oProject.ISWiPathVariables;
//Throws a no default constructor error
ISWiAuto15.ISWiPathVariable path = new ISWiPathVariable();
for (int i = 0; i < pathVariables.Count; i++)
{
path.Name = pathVariables.Name;
path.Value = pathVariables.Value;
if (path.Name.Equals(PathVariable))
{
path.Value = PathValue;
break;
}
}
oProject.SaveProject();
}
catch (Exception ex)
{
throw;
}
finally
{
oProject.CloseProject();
}
}
}
}
[/CODE]
I can't seem to get my program to work however. One problem is When i am creating my task ISWiPathVariables does not have an 'Item' member like the documentation states. I tried to work around it by looping through all objects in the ISWiPathVariables collection but I cannot create the ISWiPathVariable object. I get an error stating there is no default constructor.
Here is a trimmed down version of my code to make it easier to read. Can anyone tell me what the problem could be? I know i must just be missing something obvious.
I am using InstallShield 2009 and I have already added a reference to ISWiAutomation15.dll in my solution. I already have a task that updates the Version in the same Solution so at least something works.
[CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ISWiAuto15;
using System.IO;
namespace SetPathVariable
{
class Program
{
static void Main(string[] args)
{
bool success = false;
int ISOpenSuccess = int.MinValue;
int ISSaveSuccess = int.MinValue;
string ISMPath = @"Z:\PathToInstaller.ism";
string PathValue = @"D:\SomePath\";
string PathVariable = "PATH_TO_FILES";
string IsmName = Path.GetFileName(ISMPath);
ISWiAuto15.ISWiProject oProject = new ISWiAuto15.ISWiProject();
try
{
// Open the ISM so we can update the PathVariable
oProject.OpenProject(ISMPath, false);
ISWiAuto15.ISWiPathVariables pathVariables = new ISWiPathVariables();
pathVariables = oProject.ISWiPathVariables;
//Throws a no default constructor error
ISWiAuto15.ISWiPathVariable path = new ISWiPathVariable();
for (int i = 0; i < pathVariables.Count; i++)
{
path.Name = pathVariables.Name;
path.Value = pathVariables.Value;
if (path.Name.Equals(PathVariable))
{
path.Value = PathValue;
break;
}
}
oProject.SaveProject();
}
catch (Exception ex)
{
throw;
}
finally
{
oProject.CloseProject();
}
}
}
}
[/CODE]
(1) Reply
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Mar 30, 2009
05:40 PM
I figured this out. It turns out the collection is 1 based not 0 based.
Just in case anyone is trying to do something similar here is the updated code that works:
[CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ISWiAuto15;
using System.IO;
namespace SetPathVariable
{
class Program
{
static void Main(string[] args)
{
bool success = false;
int ISOpenSuccess = int.MinValue;
int ISSaveSuccess = int.MinValue;
string ISMPath = @"Z:\PathToInstaller.ism";
string PathValue = @"D:\SomePath\";
string PathVariable = "PATH_TO_FILES";
string IsmName = Path.GetFileName(ISMPath);
ISWiAuto15.ISWiProject oProject = new ISWiAuto15.ISWiProject();
try
{
// Open the ISM so we can update the PathVariable
oProject.OpenProject(ISMPath, false);
ISWiAuto15.ISWiPathVariables pathVariables = new ISWiPathVariables();
pathVariables = oProject.ISWiPathVariables;
for (int i = 1; i <= pathVariables.Count; i++) //collection is 1 based
{
if (pathVariables.Name.Equals(PathVariable))
{
pathVariables.Value = PathValue;
break;
}
}
oProject.SaveProject();
}
catch (Exception ex)
{
throw;
}
finally
{
oProject.CloseProject();
}
}
}
}
[/CODE]
Another thing is you need to make sure you compile to x86 if you want this to run on a 64bit OS.
Just in case anyone is trying to do something similar here is the updated code that works:
[CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ISWiAuto15;
using System.IO;
namespace SetPathVariable
{
class Program
{
static void Main(string[] args)
{
bool success = false;
int ISOpenSuccess = int.MinValue;
int ISSaveSuccess = int.MinValue;
string ISMPath = @"Z:\PathToInstaller.ism";
string PathValue = @"D:\SomePath\";
string PathVariable = "PATH_TO_FILES";
string IsmName = Path.GetFileName(ISMPath);
ISWiAuto15.ISWiProject oProject = new ISWiAuto15.ISWiProject();
try
{
// Open the ISM so we can update the PathVariable
oProject.OpenProject(ISMPath, false);
ISWiAuto15.ISWiPathVariables pathVariables = new ISWiPathVariables();
pathVariables = oProject.ISWiPathVariables;
for (int i = 1; i <= pathVariables.Count; i++) //collection is 1 based
{
if (pathVariables.Name.Equals(PathVariable))
{
pathVariables.Value = PathValue;
break;
}
}
oProject.SaveProject();
}
catch (Exception ex)
{
throw;
}
finally
{
oProject.CloseProject();
}
}
}
}
[/CODE]
Another thing is you need to make sure you compile to x86 if you want this to run on a 64bit OS.
![](/skins/images/8CE4FAD0DE6F3A6F9D0567434D2D2DAE/responsive_peak/images/icon_anonymous_message.png)