Synox
Synox

Reputation: 1160

How to use String Replace in NSIS

I use maven, I have a maven-project with version X.Y.Z-SNAPSHOT, and I use maven-nsis-plugin. Because the Version is in format X.Y.Z-SNAPSHOT, I have to remove this suffix and repace it with a 0.

The maven plugin maven-nsis-plugin generates a project.nsh:

!define PROJECT_VERSION "4.23.9-SNAPSHOT"

which is used in my setup.nsi:

!include target\project.nsh

Section VersionReplace
    Push "${PROJECT_VERSION}"
    Push "-SNAPSHOT"
    Push "0"
    Call StrRep
    Pop $0

    !define VERSION_SHORT $0
SectionEnd

Name "Installer ${VERSION_SHORT}"

(...)

VIProductVersion ${VERSION_SHORT}

Problem: In the Console i can see:

Name: "Installer $0"
(...)
VIAddVersionKey: "ProductVersion" "$0"

so the $0 is not replaced. What am I doing wrong?

Replacement function used: StrRep

Upvotes: 2

Views: 3539

Answers (2)

Synox
Synox

Reputation: 1160

This can be done using the !searchreplace command, which runs at compile time

!searchreplace PROJECT_VERSION_SHORT ${PROJECT_VERSION} "-SNAPSHOT" ".0"

Upvotes: 1

Seki
Seki

Reputation: 11465

The Name and VIProductVersion are installer attributes that are taken into account at compile time while creating the .exe

The StrRep function will be called at runtime when passing into the section VersionReplace, and it will be too late to change Name or VIProductVersion.

BTW: if you want to define some value at runtime like in your !define VERSION_SHORT $0 statement, create a variable with the Var statement and modify the variable (with StrCpy). A !define is a string replacement defined during compilation that cannot change. What you have actually written is that VERSION_SHORT is an alias for $0.

Upvotes: 0

Related Questions