Innosetup 设置文件的相对路径

在使用innosetup自动化打包的过程中,如果打包配置文件要随代码一起提交,则需要将打包文件改为相对路径,以便在其它端也可以直接打包,而不需要再次修改文件路径参数。

添加自动化打包文件

1. 添加build文件夹

Innosetup 设置文件的相对路径

2. 添加innosetup打包配置文件和cmd命令执行文件,具体可以参考 InnoSetup 以命令行自动编译打包

Innosetup 设置文件的相对路径

3. 双击执行autoBuild.bat,即可开始打包

Innosetup 设置文件的相对路径

配置文件相对路径设置

先看看当前我的配置文件:

 #define MyAppName "CompanyUserQuestion"
#define MyAppChineseName "Jira客户问题"
#define MyAppVersion "1.0"
#define MyAppPublisher "dotnet school"
#define MyAppURL "https://dotnet-campus.github.io/"
#define MyAppExeName "CompanyUserQuestion.exe" [Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{AEDA7675-70DC-479E-B796-344517C2C954}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppChineseName}
OutputDir=F:\GitHub\CompanyUserQuestion\CompanyUserQuestion\build
OutputBaseFilename={#MyAppChineseName}
SetupIconFile=F:\GitHub\CompanyUserQuestion\CompanyUserQuestion\CompanyUserQuestion\Images\bitbug_favicon.ico
Compression=lzma
SolidCompression=yes [Languages]
Name: "english"; MessagesFile: "compiler:Default.isl" [Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked [Files]
Source: "F:\Gitlab\CompanyUserQuestion\CompanyUserQuestion\CompanyUserQuestion\bin\Debug\CompanyUserQuestion.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "F:\GitHub\CompanyUserQuestion\CompanyUserQuestion\CompanyUserQuestion\bin\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons]
Name: "{group}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppName}"
Name: "{group}\{cm:UninstallProgram,{#MyAppChineseName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppName}"; Tasks: desktopicon [Run]
Filename: "{app}\{#MyAppName}"; Description: "{cm:LaunchProgram,{#MyAppChineseName}}";Flags: nowait postinstall skipifsilent

1. 相对路径

如上配置文件,是根据innosetup向导生成的打包配置,innosetup默认使用的是绝对路径,如 F:\Gitlab\CompanyUserQuestion\CompanyUserQuestion\CompanyUserQuestion\bin\Debug\CompanyUserQuestion.exe

那么,是否可以改为相对路径,更加快捷通用?

innosetup支持相对路径,所以我们可以如下修改:

  • 图标设置 SetupIconFile=..\CompanyUserQuestion\Images\bitbug_favicon.ico --返回上一层后,再进入CompanyUserQuestion文件夹选择ico图标
  • 打包输出exe目录 OutputDir=..\build -- 在当前build目录下生成打包exe;另:如果将OutputDir的设置注释,则会在build下生成一个output文件夹,打包exe;

其它的文件路径设置,可以依照如上设置相对路径引用。

2. 程序名参数匹配

在第一步设置中,有CompanyUserQuestion项目名称,这是不清真的,要统一,于是可以如下设置:

SetupIconFile=..\{#MyAppName}\Images\Jira.ico

所以相对路径优化下,我的配置文件如下:

 #define MyAppName "EasinoteUserQuestion"
#define MyAppChineseName "Jira客户问题"
#define MyAppVersion "1.0"
#define MyAppPublisher "dotnet school"
#define MyAppURL "https://dotnet-campus.github.io/" [Setup]
AppId={{AEDA7675-70DC-479E-B796-344517C2C954}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppChineseName}
OutputDir=..\build
OutputBaseFilename={#MyAppChineseName}
SetupIconFile=..\{#MyAppName}\Images\Jira.ico
Compression=lzma
SolidCompression=yes [Languages]
Name: "english"; MessagesFile: "compiler:Default.isl" [Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked [Files]
Source: "..\{#MyAppName}\bin\Debug\{#MyAppName}.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\{#MyAppName}\bin\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons]
Name: "{group}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppName}"
Name: "{group}\{cm:UninstallProgram,{#MyAppChineseName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppName}"; Tasks: desktopicon [Run]
Filename: "{app}\{#MyAppName}"; Description: "{cm:LaunchProgram,{#MyAppChineseName}}";Flags: nowait postinstall skipifsilent

提交配置文件,在其它小伙伴的电脑上,双击cmd文件,就直接可以打包最新exe

上一篇:SVN的命令解析(感觉不错就转了)


下一篇:R语言 系统聚类分析1