简体   繁体   English

如何在NSIS中使用字符串替换

[英]How to use String Replace in NSIS

I use maven, I have a maven-project with version XYZ-SNAPSHOT, and I use maven-nsis-plugin . 我使用maven,我有一个版本为XYZ-SNAPSHOT的maven项目,并且使用了maven-nsis-plugin Because the Version is in format XYZ-SNAPSHOT, I have to remove this suffix and repace it with a 0. 因为版本的格式为XYZ-SNAPSHOT,所以我必须删除此后缀并将其替换为0。

The maven plugin maven-nsis-plugin generates a project.nsh: Maven插件maven-nsis-plugin生成一个project.nsh:

!define PROJECT_VERSION "4.23.9-SNAPSHOT"

which is used in my setup.nsi: 这是在我的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. 因此不会替换$ 0。 What am I doing wrong? 我究竟做错了什么?

Replacement function used: StrRep 使用的替换功能: StrRep

这可以使用!searchreplace命令来完成,该命令在编译时运行

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

The Name and VIProductVersion are installer attributes that are taken into account at compile time while creating the .exe NameVIProductVersion是安装程序属性,在创建.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 . 传递到VersionReplace部分时,将在运行时调用StrRep函数,现在更改NameVIProductVersion为时已晚。

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 ). 顺便说一句:如果您想在运行时定义一些值,例如在!define VERSION_SHORT $0语句中,请使用Var语句创建一个变量并修改该变量(使用StrCpy )。 A !define is a string replacement defined during compilation that cannot change. !define是在编译期间!define的字符串替换,不能更改。 What you have actually written is that VERSION_SHORT is an alias for $0 . 您实际写的是VERSION_SHORT$0的别名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM