Showing posts with label Windows Installer. Show all posts
Showing posts with label Windows Installer. Show all posts

Thursday, April 16, 2009

MSI Factory & Passing Command Line Arguments to a Custom Action

I created an installer using MSI Factory. Part of my setup logic is to launch an application at the end of the installation so that the user can complete the configuration process that requires them to deploy some customizations to their Team Foundation Server (TFS). I accomplish this by using Custom Actions and pass the executable as one of its parameters the installation folder or the value of INSTALLDIR, for example. The results, however, are not as expected.

In my installer I set the Command line arguments option in the Run Executable dialog of the Custom Actions editor to the following:

-p “[INSTALLDIR]”

One would expect that the property INSTALLDIR would be replaced by the actual value. At first I thought it did not since researching about it seemed to indicate that this was the case, as it was reported that way by many.

To test the case further I decided to “hard-code” the value of the expected path to pass as an argument in the installer Custom Action and things seem to work as expected.

So, I added logic in my executable code to write to the Event Log the possible causes of this issue (errors and the actual arguments passed). The following entry would happen when I execute my application as part of my installer through a Custom Action.

Event Type:    Warning
Event Source: Process Template Item Deployer
Event Category: None
Event ID: 0
Date: 4/12/2009
Time: 3:57:28 PM
User: N/A
Computer: TFSRTM
Description:
Timestamp: 4/12/2009 7:57:28 PM
Message: System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.NormalizePathFast(String path, Boolean fullCheck)
at System.IO.Path.NormalizePath(String path, Boolean fullCheck)
at System.IO.Path.GetFullPathInternal(String path)
at System.IO.DirectoryInfo.ctor(String path)
at InCycle.Tools.Forms.ImportProcessTemplateItem.GetSupportedFilesFromPath(String path)
Category: General
Priority: -1
EventId: 0
Severity: Warning
Title:
Machine: TFSRTM
Application Domain: ProcessTemplateItemDeployer.exe
Process Id: 3956
Process Name: ProcessTemplateItemDeployer.exe
Win32 Thread Id: 3580
Thread Name:
Extended Properties:

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

I then decided to inspect previous Event Log entries and found the following interesting entry.

Event Type:    Information
Event Source: Process Template Item Deployer
Event Category: None
Event ID: 0
Date: 4/12/2009
Time: 3:57:27 PM
User: N/A
Computer: LEOV-TFSRTM
Description:
Timestamp: 4/12/2009 7:57:27 PM
Message: Attempting to load files from "C:\Temp\InstallFolder""
Category: General
Priority: -1
EventId: 0
Severity: Verbose
Title:
Machine: LEOV-TFSRTM
Application Domain: ProcessTemplateItemDeployer.exe
Process Id: 3956
Process Name: C:\Program Files\InCycle Software\InCycle Add-ons\bin\ProcessTemplateItemDeployer.exe
Win32 Thread Id: 3580
Thread Name:
Extended Properties:

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

As you can see, for some reason “[INSTALLDIR]” is expanded correctly with one small problem, it seems to pass an extra quote at the end.

I then changed my code to add logic to fix the path that I expect as an argument before I use it elsewhere in my code. The following code snippet shows you the argument extraction with the added line that fixes the problem.

// Determine if a default path has been specified from which to load files.
if ("-P".Equals(args[0].ToUpperInvariant()))
{
// Assign it for later use.
loadFilesFromPath = args[1];
// When launched from a MSI there may be invalid characters. Therefore,
// make sure to remove all such characters before proceeding.
loadFilesFromPath = loadFilesFromPath.Trim(Path.GetInvalidPathChars());
// Display debugging details.
Logger.WriteDebug(string.Format(CultureInfo.InstalledUICulture, "Attempting to load files from \"{0}\"", loadFilesFromPath));
}

Using string.Trim with Path.GetInvalidPathChars() allowed me to clean the errors from the given path.

I don’t know whether the problem lies in MSI Factory or in any underlying component, but this fixed it for me. Unfortunately, I don’t really have a way to fix this for executables for which I don’t have the code. Perhaps, writing a bootstrap application may help. But that’s another post.

Read full post...

Sunday, July 15, 2007

Making Web Setup projects run on Windows Vista

Windows Vista offers many enhancements over previous operating systems. Unfortunately for us developers it also presents some challenges. One such challenge is making a Web Setup project run on Windows Vista. This post shows step-by-step how to make it work.

Windows Vista comes pre-configured with IIS 7. Unfortunately, Web Setup projects do not recognize IIS 7 and therefore will fail when you attempt to run it on Windows Vista. In my case, the failure is presented as shown in the following figure.

Doing a lot of searching in Google presented me with nothing really obvious. As you can see from the figure above, the error message is not really helpful. Luckily, while searching for something else, I stumbled onto a MSDN article titled Troubleshooting Windows Installer Deployment. In the article I found the section Web Setup deployment projects in Visual Studio 2005 on Windows Vista, as a new section for Visual Studio 2005 SP1. The section says

When you create a Web Setup deployment project in Visual Studio 2005 on Windows Vista, you need to turn on the Windows feature IIS Metabase and IIS 6 configuration compatibility, and you need to be logged on as an Administrator; otherwise you will be unable to run setup.exe to install the project.

In order to turn on the Windows feature you can follow these steps:

1. Launch Control Panel and select Programs. This will display the Programs options.

2. In the Programs options select Turn Windows features on or off. This will display the Windows Features dialog.

3. In the Windows Features dialog expand the branch as shown in the following figure to finally select IIS Metabase and IIS 6 configuration compatibility. Select OK to install the feature.

Let Windows complete the installation. Once complete you will be able to run your Web Setup project on Windows Vista.

Read full post...