Alex
Alex

Reputation: 7612

Install directory from deployment projects

I'm developing an application and I'm going to deploy it with the help of a deployment project (which is gonna create an installer).

At one step in the installer, it will allow the user to change the installation folder for the application.

I need to know what this folder is because there will be some files saved there that I need to use from another DLL file. How can I programmatically get this installation folder?

Thank you!

Upvotes: 4

Views: 3131

Answers (2)

GilesDMiddleton
GilesDMiddleton

Reputation: 2320

If you have a really simple setup, where the current assembly is installed in the main TARGETDIR, then you can use:

String targetDir = new System.IO.FileInfo(GetType().Assembly.Location).DirectoryName;

Upvotes: 0

YWE
YWE

Reputation: 2909

Take a look at the Installer class. Add a new class derived from this class to your application's project. Don't forget to apply the RunInstaller attribute.

In your deployment project, add a Custom Action for Install and Commit. For the CustomActionData property for the Install custom action, enter /Targetdir="[TARGETDIR]\".

In your Installer class that you created in the application's project, override the Install method, and in this method you can get the installation directory like this:

string targetDir = Context.Parameters[ "TargetDir" ];

Upvotes: 6

Related Questions