這是封裝出來的針對.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
參考文章:
