Foxtable(狐表)用户栏目专家坐堂 → Setup Factory 7.0打包.NET FRAMEWORK


  共有20914人关注过本帖树形打印复制链接

主题:Setup Factory 7.0打包.NET FRAMEWORK

帅哥哟,离线,有人找我吗?
雨中的泪
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1432 积分:9061 威望:0 精华:0 注册:2009/8/19 8:19:00
Setup Factory 7.0打包.NET FRAMEWORK  发帖心情 Post By:2010/11/14 19:23:00 [只看该作者]

 

本文介绍一个工具:Setup Factory。在7.0版本中,Setup Factory的默认从属资源中仅支持VB5.0及VB6.0,想要在生成的安装程序中自动完成.NET FRAMEWORK的安装,从网上查了一下,须要按以下步骤做几件事:
首先找到Setup Factory安装目录下的Dependencies目录,在目录中新建一个dotnet2_0.xml的文件。
然后,在Dependencies目录下新建子目录,取名dotnet2_0,将.NET FRAMEWORK安装程序dotnetfx.exe拷至该子目录下,dotnetfx.exe可在VS 2005的安装目录下的SDK\\v2.0\\BootStrapper\\Packages\\dotnetfx目录下找到。
完成之后打开Setup Factory,选择:资源---从属---添加,可以看到.NET FRAMEWORK 2.0了。
文件dotnet2_0.xml内容如下:


<DependencyTemplate>

<Dependency>

<Name>Microsoft .NET Framework 2.0</Name>

<RuntimeTempFolder>dotnet2_0</RuntimeTempFolder>

<RevisionDate>Friday, March 30, 2007</RevisionDate>

<Description>安装 Microsoft .NET Framework 2.0应用程序所需的运行时文件。</Description>

<DetectScript>

function isDotNet_Installed()

--author:zhengxinhe www.admans.net

-- Output to the log that the .NET detection has started.

SetupData.WriteToLogFile("Success\t.NET 2.0 Module: Detection script started.\r\n", true);

-- Get the operating system name.

--Check to see if the registry key exists

DotNet_Registry = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\.NETFramework");

if (DotNet_Registry == nil) then

-- The registry key does not exist

-- Run the .NET Installation script

-- Output to the log file that .NET could not be found, so it will be installed.

SetupData.WriteToLogFile("Info\t.NET 2.0 Module: No version of .NET 2.0 files was found. .NET 2.0 will be installed.\r\n", true);

return false;

end

-- The key does exist

-- Get the .NET install location from the registry

DotNet_Install_Location = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\.NETFramework", "InstallRoot", true);

-- Look for the file mscorcfg.dll

Does_File_Exist = DotNet_Install_Location.."\\v2.0.50727\\aspnet_rc.dll";

if(not File.DoesExist(Does_File_Exist))then

-- The file does not exist

-- Run the .NET Installation script

-- Output to the log file that .NET could not be found, so it will be installed.

SetupData.WriteToLogFile("Info\t.NET 2.0 Module: No version of .NET 2.0 file was found. .NET 2.0 will be installed.\r\n", true);

return false;

end

-- The file does exist

-- Get the version of mscorcfg.dll

msc_ver = File.GetVersionInfo(Does_File_Exist);

if(not msc_ver)then

SetupData.WriteToLogFile("Info\t.NET 2.0 Module: no version was found. .NET 2.0 will be installed.\r\n", true);

return false;

end

-- Compare the returned value against the needed value

Compare = String.CompareFileVersions(msc_ver.FileVersion, "2.0.50727.42");

if (Compare == -1) then

-- Output to the log file that a lesser version of .NET was found on the system

SetupData.WriteToLogFile("Info\t.NET 2.0 Module: A lesser version of .NET 2.0("..msc_ver.FileVersion..") was found on the users system.\r\n", true);

return false;

else

-- a version less than version 2.0 is installed

-- Output to the log file that a lesser version of .NET was found on the system

SetupData.WriteToLogFile("Info\t.NET 2.0 Module: A new or this version of .NET 2.0 was found on the users system.\r\n", true);

return true;

end

end

</DetectScript>

<DetectFunction>isDotNet_Installed</DetectFunction>

<InstallScript>

-- 用在安装操作中的变量:

local strMessage = [[安装程序检测到你的系统没有安装Microsoft .NET Framework2.0或者版本过旧。请点击“确定”进行安装,点击“取消”中止安装。]];

local strDialogTitle = "必需的技术文件";

local bShowUserPrompt = true; -- 设置为 true 来询问用户是否安装模块

local bRunInstallFile = true; -- 设置默认选择 (是否默认运行安装)

local strRuntimeSupportFolder = SessionVar.Expand("%TempLaunchFolder%\\dotnet2_0");

local strFileToRun = strRuntimeSupportFolder.."\\dotnetfx.exe";

-----------------------------------------------------------------------------------------

-- 安装已启动。

SetupData.WriteToLogFile("成功\tdotnet2_0 模块:安装脚本已启动。\r\n", true);

-- 删除临时文件和运行时支持文件夹 (同时进行错误检查)

local function PerformCleanUp()

File.Delete(strFileToRun);

error = Application.GetLastError();

if error ~= 0 then

SetupData.WriteToLogFile("错误\tdotnet2_0 模块:无法删除临时文件 (".._tblErrorMessages[error]..")\r\n", true);

end

Folder.Delete(strRuntimeSupportFolder);

error = Application.GetLastError();

if error ~= 0 then

SetupData.WriteToLogFile("错误\tdotnet2_0模块:无法删除临时文件夹 (".._tblErrorMessages[error]..")\r\n", true);

end

end

-- 是否显示对话框来询问用户是否安装模块。

if(bShowUserPrompt)then

local nDialogResult = Dialog.Message(strDialogTitle,strMessage,MB_OKCANCEL,MB_ICONEXCLAMATION);

if(nDialogResult == IDOK)then

-- 用户选择安装模块。

bRunInstallFile = true;

-- 用户要安装它

SetupData.WriteToLogFile("成功\tdotnet2_0 模块:用户已确认,准备安装。\r\n", true);

else

-- 用户不安装模块。

bRunInstallFile = false;

-- 用户回答否

SetupData.WriteToLogFile("成功\tdotnet2_0 模块:用户不安装模块。\r\n", true);

end

end

-- 检查用户是否要安装运行时。

if(bRunInstallFile)then

-- 开始!

SetupData.WriteToLogFile("成功\tdotnet2_0模块:正在运行dotnet2_0 安装程序。\r\n", true);

-- “/R:N”命令行参数告诉 VB 安装程序若需要的话不要显示重启屏幕。

-- 我们将检测整个安装进程返回代码,若需要的话,还设置内部 _NeedsReboot 变量。

-- 【注意】在静默方式下,你不能添加命令行参数“/Q”来运行安装

local nResult = File.Run(strFileToRun,"/R:N","",SW_SHOWNORMAL,true);

if(nResult == 3010)then

-- VB 安装指明它需要重启才能完成

-- 设置 Setup Factory 的重启变量,以便在安装结束时重启

_NeedsReboot = true;

-- 需要重启

SetupData.WriteToLogFile("成功\tdotnet2_0 模块:dotnet2_0 安装程序已告知它需要重启。\r\n", true);

end

-- 删除运行时安装程序文件,并删除临时文件夹

PerformCleanUp();

-- 全部完成!

SetupData.WriteToLogFile("成功\tdotnet2_0模块:dotnet2_0运行时安装完毕。\r\n", true);

else

-- 用户不想安装运行时,那么删除运行时安装程序文件,

-- 并删除临时文件夹,然后退出安装程序。

PerformCleanUp();

-- 全部完成!

SetupData.WriteToLogFile("成功\tdotnet2_0 模块:dotnet2_0 运行时未安装。\r\n", true);

Application.Exit();

end

</InstallScript>

<SupportFiles>

<File>#SUFDIR#\Dependencies\dotnet2_0\dotnetfx.exe</File>

</SupportFiles>

</Dependency>

</DependencyTemplate>


 回到顶部