VSoft Technologies Blogs

rss

VSoft Technologies Blogs - posts about our products and software development.

Using relative paths in a project is a good idea - they make a project more maintainable, readable and portable.

However, lately I've seen quite a few sample FinalBuilder projects where people are using this kind of relative path in their actions:

MySolutionFile.sln
.\MyProject\Installer\Project.iss
..\..\MyOtherProject\MyProject.dproj

The idea is that if the file is located relative to the project file path, the relative path will resolve to the right directory.

Great idea, right? Unfortunately, no.

These relative paths rely on the current Windows working directory for the process. Unfortunately, FinalBuilder and Automise only have limited control over this property. Various API calls (made by actions, scripts or the IDE) might change this directory unexpectedly.

The safe way to use relative paths in a FinalBuilder or Automise project is to use the variable %FBPROJECTDIR% (called %PROJECTDIR% in Automise.) This variable evaluates to the directory which contains the current project file.

Unsafe Safe
MySolution.sln %FBPROJECTDIR%\MySolution.sln
.\MyProject\ %FBPROJECTDIR%\MyProject\Installer\Project.iss
..\..\MyOtherProject\MyProject.dproj %FBPROJECTDIR%\..\..\MyOtherProject\MyProject.dproj

We recommend defining new project variables to prevent these paths from becoming too long and unwieldy, and to make your project easier to read.

For instance, you could define a project variable called InstallerPath and set it to %FBPROJECTDIR%\MyProject\Installer. Turn on the "Macro" option for the InstallerPath variable to make sure variable references are expanded each time the variable is read.

Add Macro Variable

Showing 4 Comments

Avatar
NK 17 years ago

>Just be warned that a couple of applications (I forget which, sorry) don't work with subst drives.<br><br>Perhaps it's 'AQTime', isn't it ?<br>I don't know any other apps.<br><br>'F12' features seems good.<br>#I have to make time to try FB6 Beta... :-)


Avatar
angus 17 years ago

(Sorry about the comment formatting. I'll try and get it fixed.)


Avatar
angus 17 years ago

Hi NK,<br><br>There is a feature to help with this automatic replacement in the new FB 6 beta (you can press F12 in any dialog and it automatically suggests variables than can be substitued-in to make the reference shorter.)<br><br>Alternatively, you can just use Search/Replace.<br><br>The subst drive trick is a good one, we use it here for our development "drives". Just be warned that a couple of applications (I forget which, sorry) don't work with subst drives.<br><br>Instead of the subst drive you could also just create a FinalBuilder variable called BuildRoot (or similar), and set it to the absolute path of your project root directory.<br><br>Regards,<br><br>Angus


Avatar
NK 17 years ago

I use 'subst drive'. I always set project root to "B" drive at the first action. (B is for 'B'uild :)<br>It's difficult to convert all absolute paths to relative in big project.<br>(It's tough to debug, because it's work with absolute path on the first PC, and we have to find and replace them. So, I gave up to use %FBPROJECTDIR% on my current project.)<br>with subst, all open dialogs, etc can be used without converting abs path to rel path with %FBPROJECTDIR%.<br><br>If IDE could automatically substitute such as B:\ to %FPPROJECTDIR%\, we can use GUI to specify dir, files, etc, and also can eliminate absolute path without annoying search.<br><br>Ah, this could be done with FB's XML/ZIP support, couldn't it ? ;-)



Comments are closed.