Click here to Skip to main content
Licence 
First Posted 30 Apr 2007
Views 11,948
Bookmarked 9 times

How to persist DIRs past SETUP wizard

By | 30 Apr 2007 | Article
How to Find Directory Path before and after setup wizard deployment

Introduction

Using .NET ... how do you find your support directories and files before and after Setup Deployment.

Let's say ... you've got a .NET WinForm app. The app uses several support files which must be installed during setup. You're using a standard 2005 setup project.

Do you relize how "tricky-cool" the IDE really is?
Ok, here's how it works.

Application.ExecutablePath returns either "MyProject/bin/debug" or "MyProject/bin/release" depending on the build configuration. BUT ... once MSI wrapped and installed then Application.ExecutablePath returns "ProgramFiles/Manuf/MyProject".

So, the blasted PATH CHANGES! Meaning, any subdirectory/file you wanted to FIND during development and ALSO find after deployment ends up in THREE POSSIBLE PLACES!!!! RATS ...

Any file (or subdirectory) you want to be included in the final SETUP msi needs to have it's "Build Action" property set to "Content" then all the subdirectories-and-files are copied during setup to the installer [TargetDirectory].

HOWEVER, and here's the TRICKY part, there's another property for each file called "Copy To Output Directory" which needs to be set to "CopyAlways" ... then ... everytime you run the app in the IDE, the debugger FIRST copies all the files so marked into the appropriate "bin/debug" or "bin/release" directory BEFORE RUNNING! Every time you run! Every time it copies! So, using Application.ExecutablePath always works! While using debug in the IDE and after deployment.

Using the code

Here's how I do it now ...
I have a static class file called funcs.cs ....

public class funcs
{
     private static string mBasePath="";
     public funcs()
     {
     }
     public static string BasePath
     {
          get { return mBasePath; }
          set { mBasePath = value; }
     }
}

Then ... in my Main initialization, I set the static BasePath ... like this ...

[STAThread] 
static void Main()
{
      fn.BasePath = Application.ExecutablePath.Substring(0, 1 + Application.ExecutablePath.LastIndexOf("\\"));
      Application.Run(new frmMain());
}

And finally, anytime I need to build a path name, I just use BasePath!

PicsHomePath = fn.BasePath + "pics\\";

As long as "Copy To Output Directory" for each file is set to "CopyAlways" then your code FINDS the right path, whether your runing in the IDE or after installation!

Points of Interest

I know, seems simple ... it is simple once you know the "trick"

History

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

KinnMirr

Web Developer

United States United States

Member

Ugly Old Fat Guy (grin).

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralSo Pinmembermaabd0:09 9 May '07  
GeneralRe: So PinmemberFlashSand4:37 9 May '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 30 Apr 2007
Article Copyright 2007 by KinnMirr
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid