Innosetup 设置文件的相对路径

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

添加自动化打包文件

1. 添加build文件夹

Innosetup 设置文件的相对路径

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

Innosetup 设置文件的相对路径

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

Innosetup 设置文件的相对路径

 

配置文件相对路径设置

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

 1 #define MyAppName "CompanyUserQuestion"
 2 #define MyAppChineseName "Jira客户问题"
 3 #define MyAppVersion "1.0"
 4 #define MyAppPublisher "dotnet school"
 5 #define MyAppURL "https://dotnet-campus.github.io/"
 6 #define MyAppExeName "CompanyUserQuestion.exe"
 7 
 8 [Setup]
 9 ; NOTE: The value of AppId uniquely identifies this application.
10 ; Do not use the same AppId value in installers for other applications.
11 ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
12 AppId={{AEDA7675-70DC-479E-B796-344517C2C954}
13 AppName={#MyAppName}
14 AppVersion={#MyAppVersion}
15 ;AppVerName={#MyAppName} {#MyAppVersion}
16 AppPublisher={#MyAppPublisher}
17 AppPublisherURL={#MyAppURL}
18 AppSupportURL={#MyAppURL}
19 AppUpdatesURL={#MyAppURL}
20 DefaultDirName={pf}\{#MyAppName}
21 DefaultGroupName={#MyAppChineseName}
22 OutputDir=F:\GitHub\CompanyUserQuestion\CompanyUserQuestion\build
23 OutputBaseFilename={#MyAppChineseName}
24 SetupIconFile=F:\GitHub\CompanyUserQuestion\CompanyUserQuestion\CompanyUserQuestion\Images\bitbug_favicon.ico
25 Compression=lzma
26 SolidCompression=yes
27 
28 [Languages]
29 Name: "english"; MessagesFile: "compiler:Default.isl"
30 
31 [Tasks]
32 Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
33 
34 [Files]
35 Source: "F:\Gitlab\CompanyUserQuestion\CompanyUserQuestion\CompanyUserQuestion\bin\Debug\CompanyUserQuestion.exe"; DestDir: "{app}"; Flags: ignoreversion
36 Source: "F:\GitHub\CompanyUserQuestion\CompanyUserQuestion\CompanyUserQuestion\bin\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
37 ; NOTE: Don't use "Flags: ignoreversion" on any shared system files
38 
39 [Icons]
40 Name: "{group}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppName}"
41 Name: "{group}\{cm:UninstallProgram,{#MyAppChineseName}}"; Filename: "{uninstallexe}"
42 Name: "{commondesktop}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppName}"; Tasks: desktopicon
43 
44 [Run]
45 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

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

 1 #define MyAppName "EasinoteUserQuestion"
 2 #define MyAppChineseName "Jira客户问题"
 3 #define MyAppVersion "1.0"
 4 #define MyAppPublisher "dotnet school"
 5 #define MyAppURL "https://dotnet-campus.github.io/"
 6 
 7 [Setup]
 8 AppId={{AEDA7675-70DC-479E-B796-344517C2C954}
 9 AppName={#MyAppName}
10 AppVersion={#MyAppVersion}
11 AppPublisher={#MyAppPublisher}
12 AppPublisherURL={#MyAppURL}
13 AppSupportURL={#MyAppURL}
14 AppUpdatesURL={#MyAppURL}
15 DefaultDirName={pf}\{#MyAppName}
16 DefaultGroupName={#MyAppChineseName}
17 OutputDir=..\build
18 OutputBaseFilename={#MyAppChineseName}
19 SetupIconFile=..\{#MyAppName}\Images\Jira.ico
20 Compression=lzma
21 SolidCompression=yes
22 
23 [Languages]
24 Name: "english"; MessagesFile: "compiler:Default.isl"
25 
26 [Tasks]
27 Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
28 
29 [Files]
30 Source: "..\{#MyAppName}\bin\Debug\{#MyAppName}.exe"; DestDir: "{app}"; Flags: ignoreversion
31 Source: "..\{#MyAppName}\bin\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
32 ; NOTE: Don't use "Flags: ignoreversion" on any shared system files
33 
34 [Icons]
35 Name: "{group}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppName}"
36 Name: "{group}\{cm:UninstallProgram,{#MyAppChineseName}}"; Filename: "{uninstallexe}"
37 Name: "{commondesktop}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppName}"; Tasks: desktopicon
38 
39 [Run]
40 Filename: "{app}\{#MyAppName}"; Description: "{cm:LaunchProgram,{#MyAppChineseName}}";Flags: nowait postinstall skipifsilent

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

上一篇:inno setup win10 创建菜单里面卸载图标


下一篇:插入触发器后的MySQL获取自动递增值,插入后更新字段值给出“未知列”错误