Alex Leitsin
Alex Leitsin

Reputation: 67

Get current directory from setup project

I create a setup project in Install Shield Limited Edition Visual Studio for Windows 7.

In this project I need to run a C# application as Customer Action During Installation. In this C# application I need path from where setup project runs. I tried to use GetCurrentProcess().MainModule.FileName or GetExecutionAssembly(). Location or Envirement.CurrentDirectory. All this functions work from the application. But if I add this program to set up project as Custom Action During installation I get path to C:\Windows.

How can I get real path ?
Thanks

Upvotes: 4

Views: 1704

Answers (2)

Nazmul Hasan
Nazmul Hasan

Reputation: 10590

you have to added the custom installer to your install project in the Custom Actions pain. Select the Install action and set the CustomActionData property to:

/targetdir="[TARGETDIR]\"

Then you can access the path like this:

[RunInstaller(true)]
public partial class CustomInstaller : System.Configuration.Install.Installer
{
    public override void Install(System.Collections.IDictionary stateSaver)
    {
        base.Install(stateSaver);
        string path = this.Context.Parameters["targetdir"]; 
        // Do something with path.
    } 
}

more https://msdn.microsoft.com/en-us/library/system.configuration.install.installer(v=vs.90).aspx

if you get any issue let me know

Upvotes: 4

Mostafiz
Mostafiz

Reputation: 7352

You can get application directory

string directory = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

or

string directory = System.AppDomain.CurrentDomain.BaseDirectory;

or

string directory = Thread.GetDomain().BaseDirectory;

Upvotes: 1

Related Questions