Search code examples
constantsnsis

How do I use a constant to specify a File path in NSIS?


I'd like to use a constant to specify the directory where the files to be installed live, like this:

; -*-nsis-*-

Name "ndhtest"
OutFile "FooStartMenuTest.exe"

!define FOO_SRC c:\users\nhughes\foo

InstallDir "$PROGRAMFILES\Initech\"

Page instfiles
Section
  SetOutPath $INSTDIR
  File "$FOO_SRC\foo.bat"    ;; <-- line 15 here
  CreateDirectory $SMPROGRAMS\Initech
  CreateShortCut $SMPROGRAMS\Initech\Foo.lnk $INSTDIR\foo.bat "" \
    "$FOO_SRC\foo_logo.ico"  ;; <-- line 18 here
SectionEnd

This causes the following error message (in emacs, using nsis-mode):

Processing script file: "c:/users/nhughes/STARTM~1.NSI"
Name: "ndhtest"
OutFile: "FooStartMenuTest.exe"
XPStyle: on
!define: "FOO_SRC"="c:\users\nhughes\foo"
InstallDir: "$PROGRAMFILES\Initech\"
Page: instfiles
Section: ""
SetOutPath: "$INSTDIR"
File: "$FOO_SRC\foo.bat" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
   /oname=outfile one_file_only)
Error in script "c:/users/nhughes/STARTM~1.NSI" on line 15 -- aborting creation process

If I replace line 15 with

File c:\users\nhughes\foo\foo.bat

and line 18 with

  "c:\users\nhughes\foo\foo_logo.ico"

then it works fine.


Solution

  • Try using ${FOO_SRC} instead.