之前通过NSIS打包文件后来发现Inno Setup,使用了一下发现相较于NSIS个人感觉Inno稍微好一点,整个操作界面会比NSIS要简洁许多,有汉化版可以添加我这里用的是英文原版
向导设置
- 安装后创建新的文件向导 File-> New

- 点击Next进入设置界面
因为打包的安装包大部分是放在指定的文件夹中所以选择文件夹
3. 因为Revit插件是基于Reivt二次开发的插件所以没有启动项勾选下面的即可,如果有其他的文件也可以,这个地方我没有尝试加入文件夹,后续的文件夹我直接再脚本中新增
同样因为没有启动项我们也不需要创建开始菜单,这里点掉就可以了
4. 添加许可文件等信息
5. 添加安装权限这个位置后续也是可以通过脚本编辑
6. 选择语言,因为我没有安装汉化包所以只有选择英文
6. 其他设置
7. 完成,之后进入脚本编辑内容

脚本设置
具体的内容可以看Inno的API进行学习操作,这里说一下我用到的节点
- 有时我们需要将安装包中某些文件安装到系统路径中,Inno这里提供了一些系统路径的节点,可以看API中Constants节点,其中
- {app} 用户安装路径
- {localappdata} C:\Users\user\AppData\Local
- {appdata} C:\Users\xu.lanhui\AppData\Roaming
- Source 这里我是用Source添加了公司内部的登录确认工具,并让其安装到单独的路径中
Source: "C:\Users\xu.lanhui\Desktop\registor\*";DestDir:"{localappdata}\***\registor" ; Flags: ignoreversion recursesubdirs createallsubdirs
```ini
3. [Run] 复制多个addin文件
因为可以调用外部应用程序,可以使用擅长的语言写文件Copy的程序,使用Inno调用即可,下面是我的传入参数
[Run] Filename: “{app}\CopyFiles.exe” ;Description:“修改文件” ; Parameters:"""{app}"""; StatusMsg: “正在配置信息”; Flags: runhidden
## 全部脚本编码及C#复制addin到版本文件
1. Inno脚本编码
; Script generated by the Inno Setup Script Wizard. ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName “BiMass” #define MyAppVersion “1.4.2” #define MyAppPublisher “TYDI”
[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={{3B7C7466-9BA0-44B3-80D8-87DDF9997572} AppName={#MyAppName} AppVersion={#MyAppVersion} ;AppVerName={#MyAppName} {#MyAppVersion} AppPublisher={#MyAppPublisher} DefaultDirName={autopf}{#MyAppName} DefaultGroupName={#MyAppName} DisableProgramGroupPage=yes LicenseFile=D:\000 Development&TemplateFloder\Panel\Document.rtf ; Uncomment the following line to run in non administrative install mode (install for current user only.) ;PrivilegesRequired=lowest OutputDir=D:\000 Development&TemplateFloder\Panel\Output OutputBaseFilename=Setup Compression=lzma SolidCompression=yes WizardStyle=modern PrivilegesRequired=admin UsedUserAreasWarning = no
[Dirs] Name: “{localappdata}***\registor”
[Languages] Name: “english”; MessagesFile: “compiler:Default.isl”
[Files]
Source: “D:\000 Development&TemplateFloder\Panel\Panel\Install*”; DestDir: “{app}”; Flags: ignoreversion recursesubdirs createallsubdirs Source: “C:\Users\user\Desktop\registor*“;DestDir:“{localappdata}\TengYuanTmp\registor” ; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don’t use “Flags: ignoreversion” on any shared system files
[Run] Filename: “{app}\CopyFiles.exe” ;Description:“修改文件” ; Parameters:"""{app}"""; StatusMsg: “正在配置信息”; Flags: runhidden
2. C# 复制许可文件到版本addin中
- 这事我的文件架构

- code
// See https://aka.ms/new-console-template for more information
using System; using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; using System.Text.RegularExpressions;
Console.WriteLine(“Start Changing”); string path = string.Empty; if(args.Length < 1) { path = System.Environment.CurrentDirectory; } else { path = args[0]; }
Console.WriteLine(path); try { var localFile = @”.\ProductName.addin”; var strContent = File.ReadAllText(localFile);
CopyFiles(strContent, path);
} catch (Exception e) {
Console.WriteLine(e.ToString());
throw;
} Console.WriteLine(“Done”); //Console.ReadKey(); return;
bool CopyFiles(string strContent, string targetPath) {
if (strContent == null) throw new ArgumentNullException(nameof(strContent));
if (targetPath == null) throw new ArgumentNullException(nameof(targetPath));
int[] versions = new[] { 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 };
// 将数据copy到其他版本文件中,如果路径下不存在该文件夹则创建新文件夹
//const string localProgramDataPath = @"C:\ProgramData\Autodesk\Revit\";
const string localReplacePath = @"E:\\Productname\\RibbonPanel\\Panel\\bin\\Debug\\Panel.dll";
const string localDataPath = @"C:\ProgramData\Autodesk\Revit\Addins";
foreach (int version in versions)
{
string? content = strContent.Clone() as string;
var fullPath = @$"{targetPath}\{version}";//代表用户的安装路径
Console.WriteLine($"fullPath:{fullPath}");
var localFullPath = @$"{localDataPath}\{version}";//代表peogramdata文件夹路径
//查找C盘路径是否提前创建该文件夹,如果没有则新建
if (!File.Exists(localFullPath))
{
Directory.CreateDirectory(localFullPath);
Console.WriteLine(localFullPath);
}
//查找安装位置是否有着指定版本安装文件,没有的话跳过
if (Directory.Exists(fullPath))
{
if (content != null)
{
content = Regex.Replace(content, @localReplacePath, fullPath + @$"\Productname_{version}.dll");
Console.WriteLine(content);
File.WriteAllText(localFullPath + @"\Productname.addin", content);
}
}
//Console.WriteLine($"localPath:{fullPath}");
}
return false;
}