komodosp
komodosp

Reputation: 3658

Installer Project Custom Actions - Specify working directory

I have a custom action that runs as a Visual Studio Installer Projects deployment.

Is it possible to specify the working directory of this custom action, relative to the installation directory?

Edit

To clarify

I have an installer project that runs a program as a custom action. I want to specify the working directory of that program from within the installer project, so when the program runs during installation, it will run with the Working directory I specified at the time of creating the installer.

Upvotes: 0

Views: 2127

Answers (2)

PhilDW
PhilDW

Reputation: 20790

You could pass a working directory into the program on the command line arguments, but only if the program is designed to take the value and use it as its working directory. Alternatively the program could just derive its running directory with code like this:

> public static string GetAssemblyPathByCodeBase() {
>     string codeBase = Assembly.GetExecutingAssembly().CodeBase;
>     UriBuilder uri = new UriBuilder(codeBase);
>     return Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path)); }

The general problem is that when the program is run from (say) a double click then the Explorer shell sets the working directory to be the hosting directory. Windows Installer doesn't do that.

Upvotes: 0

Stein Åsmul
Stein Åsmul

Reputation: 42236

Working Directory: Is this an EXE custom action? Custom actions in Visual Studio Installer Projects run in deferred mode, system context - meaning they run as System / LocalSystem. I am honestly not sure what that does to the "working folder". I would assume it just means the working folder is wherever the executable is running from.

VS Installer Project Limitations: Visual Studio Installer Projects lack the ability to configure advanced settings altogether. There is a way to run an EXE file and specify a working folder, but it is not supported by these projects. I am also not sure if this would solve your problem before we know what you are actually running. It could be a script. There are several major problems with these installer projects.

Custom Action: A Type 34 Custom Action allows you to Run an EXE file having a path referencing a directory. You either need to hotfix your output MSI with Orca or use a real-deployment tool such as WiX or an equivalent commercial options. Though I have not tried, WiX should be capable of doing what you want - as should all the other, major commercial options.

Hotfixing: Hotfixing the MSI is somewhat involved meaning you have to add entries to the CustomAction Table and the InstallExecuteSequence Table. You should not need to add the binary to the Binary Table if it is a file you want to run after it is installed or it is a file that exists on disk already. There are a number of flags you need to set for the custom action column Type which relates to whether the action runs synchronously or asynchronously, whether you want to abort on error or not, what sequence it will run in and that kind of stuff. You combine bit fields.

Upvotes: 1

Related Questions