Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current directory from setup project

Tags:

c#

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

like image 918
Alex Leitsin Avatar asked Sep 06 '25 22:09

Alex Leitsin


2 Answers

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

like image 200
Nazmul Hasan Avatar answered Sep 10 '25 16:09

Nazmul Hasan


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;
like image 30
Mostafiz Avatar answered Sep 10 '25 14:09

Mostafiz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!