Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a file's contents into a variable/define in NSIS?

I have a file 'releaseVersionNumber.txt' which I read during my build process; currently its read for my Mac build but I want to read it in my Windows NSIS build to reduce the number of edit locations (duplication being evil)...

So I'm trying to replace:

!define VERSION 1.2.3

with something like

FileOpen $4 "..\releaseVersionNumber.txt" r
FileRead $4 $1
FileClose $4
!define VERSION ${1}

But I get an error command FileOpen not valid outside Section or Function. Wrapping it in a function I produces command call not valid outside Section or Function so I can't seem to do this in the installer setup, only at runtime.

Is there a way to achieve what I'm after?!

like image 247
Justin Avatar asked Mar 26 '13 08:03

Justin


1 Answers

All commands begining with ! are compile time commands, so they are processed at compile time, much before your program runs.

  • You can try declaring VERSION as a Variable instead of a define:

    Var VERSION
    FileOpen $4 "..\releaseVersionNumber.txt" r
    FileRead $4 $VERSION
    FileClose $4
    
  • If you need VERSION to be a define, then you can try the /file parameter in !define.

    !define /file VERSION "..\releaseVersionNumber.txt"
    
  • I like to have a version.nsh file with just the define:

    !define VERSION "2013-03-25:16:23:50"
    

    And then, I include it:

    !include /NONFATAL version.nsh
    # Default value in case no version.nsh is present
    !ifndef VERSION
        !define /date VERSION "%Y-%m-%d %H:%M:%S"
    !endif
    
like image 126
Francisco R Avatar answered Sep 30 '22 19:09

Francisco R