InnoSetup打包 添加.NET环境安装
这是封装出来的针对.NET环境安装的精简流程
根据流程新建一个配置文件
教程都是很简单的,可以参考《InnoSetup 客户端程序打包教程》
添加.NET安装基本的函数及辅助方法
在[Setup]模块下引用几个辅助文件
1 //import dependency for .net 2 //isxdl operation 3 #include "dependency\isxdl.iss" 4 //;TYPES AND VARIABLES 5 #include "dependency\products.pas" 6 //about .net versions 7 #include "dependency\dotnetfxversion.iss"
isxdl.iss -- 引用了isxdl.dll并添加文件下载、安装函数
products.pas -- 版本的安装过程
dotnetfxversion.iss -- .net版本信息等相关函数
添加.NET版本引用及启动执行
以.net4.5.iss为例,添加了版本的信息及下载地址等(下载过程调用上个步骤中product.pas函数)
1 [CustomMessages] 2 dotnetfx45_title=.NET Framework 4.5.2 3 dotnetfx45_size=68 MB 4 5 [Code] 6 const 7 dotnetfx45_url = 'http://download.microsoft.com/download/B/4/1/B4119C11-0423-477B-80EE-7A474314B347/NDP452-KB2901954-Web.exe'; 8 9 procedure dotnetfx45(minVersion: Integer); 10 begin 11 if (dotnetfxspversion(NetFx4x, '') < minVersion) then 12 AddProduct('dotnetfx45.exe', 13 '/lcid ' + CustomMessage('lcid') + ' /passive /norestart', 14 CustomMessage('dotnetfx45_title'), 15 CustomMessage('dotnetfx45_size'), 16 dotnetfx45_url, 17 false, false, false); 18 end;
在[Setup]中添加要依赖的.NET版本:
1 [Setup] 2 //add .net4.5 3 #include "dependency\.net versions installation\dotnetfx45.iss" 4 #include "dependency\.net versions installation\dotnetfx46.iss"
添加定制语言项,如果安装包需要支持多语种,可以额外引用其它语言项进行选择。
1 [CustomMessages] 2 DependenciesDir=MyProgramDependencies 3 WindowsServicePack=Windows %1 Service Pack %2 4 //固定英文安装语言 5 lcid=1033 6 depdownload_memo_title=Download dependencies 7 depinstall_memo_title=Install dependencies 8 depinstall_title=Installing dependencies 9 depinstall_description=Please wait while Setup installs dependencies on your computer. 10 depinstall_status=Installing %1... 11 depinstall_missing=%1 must be installed before setup can continue. Please install %1 and run Setup again. 12 depinstall_error=An error occured while installing the dependencies. Please restart the computer and run the setup again or install the following dependencies manually:%n 13 isxdl_langfile=""
安装.NET版本:
1 [Code] 2 function InitializeSetup(): Boolean; 3 begin 4 dotnetfx45(50); // install if version < 4.5.0 5 dotnetfx46(60); // install if version < 4.6.0 6 Result := true; 7 end;
需要什么版本,直接加一行代码就行~
Demo案例
点击安装后,会自动检测.NET环境,并执行缺失环境的安装。
安装成功后,就可以正常启动咯~
demo案例详见 https://github.com/Kybs0/InnoSetupAddNETVersionsDemo
参考文章:
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 易语言 —— 开山篇