为什么 Inno Setup 常量 {userdesktop} 在 OutputDir 指令中不起作用以及如何修复它?

Con*_*alo 1 inno-setup

我创建了 Inno Setup 脚本,它运行良好,但我想更改OutputDir为在我的桌面上创建输出文件。但是不是在桌面上创建输出文件,而是{userdesktop}在同一目录中创建子文件夹,脚本所在的位置和输出在其中。

到目前为止我找到了解决方案,但我相信应该有更好的方法。我错过了什么?

; these attempts didn't work
[Setup]
OutputDir={userdesktop}
; some more attampts:
OutputDir=userdesktop
OutputDir=userdesktop:
OutputDir="{userdesktop}"

; this workaround worked for me
[Setup]
OutputDir=userdocs:..\Desktop
Run Code Online (Sandbox Code Playgroud)

Mar*_*ryl 6

诸如此类{userdesktop}常量是在安装时(在目标用户机器上)解决的,而不是在编译时(在您的开发机器上)。所以在像OutputDir. 实际上根本不可能使用它们(因为它没用)。

使用默认的用户配置文件目录布局,使用您可以使用userdocs:前缀,就像您所做的那样:

[Setup]
OutputDir=userdocs:..\Desktop
Run Code Online (Sandbox Code Playgroud)

虽然这不是一个完美的解决方案,因为“文档”文件夹可以由用户移动,然后userdocs:..\Desktop不会指向桌面。

更可靠的解决方案是使用预处理器函数使用USERPROFILE环境变量GetEnv

[Setup]
OutputDir={#GetEnv('USERPROFILE')}\Desktop
Run Code Online (Sandbox Code Playgroud)