简体   繁体   English

如何将文件的内容加载到NSIS中的变量/ define中?

[英]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; 我有一个文件'releaseVersionNumber.txt',我在构建过程中读到了该文件; 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)... 目前它为我的Mac版本阅读,但我想在我的Windows NSIS版本中阅读它以减少编辑位置的数量(重复是邪恶的)...

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 . 但是我得到一个错误命令FileOpen在Section或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. 将它包装在函数中我生成的命令调用在Section或Function之外无效,所以我似乎无法在安装程序设置中执行此操作,仅在运行时。

Is there a way to achieve what I'm after?! 有没有办法实现我追求的目标?!

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: 您可以尝试将VERSION声明为变量而不是定义:

     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 . 如果您需要VERSION作为定义,那么您可以在!define中尝试/file参数。

     !define /file VERSION "..\\releaseVersionNumber.txt" 
  • I like to have a version.nsh file with just the define: 我喜欢只有define的version.nsh文件:

     !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 

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

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