|
制作自己的native安装程序
如果我们要把自己的.net程序发布到目标机器上,同时我们不确定该目标机器是否已经安装了.net framework, 那我们就需要自己设计一段unmanaged代码,来判断目标机器是否安装了.net framework, 如果没有,则运行dotnetfx.exe安装.net framework, 然后利用windows installer安装自己的程序。
在msdn的下面网页上,我们可以获得一个使用unmanaged c++实现的安装程序和它的源代码:
http://msdn.microsoft.com/downlo ... sdncompositedoc.xml
1.在csettings class中,通过读取"settings.ini",获得您自己的msi安装文件和dotnetfx.exe的路
径,以及其他您自己的设置。(比如.net framework的语言版本)
getcaptiontext(void)
getdialogtext(void)
geterrorcaptiontext(void)
getininame(void)
getproductname(void)
parse()函数用来解析settings.ini文件。
2.在main.cpp文件中,全局函数fxinstallrequired()判断是否要在目标机器上安装.net framework. fxinstallrequired()会检测下面的注册表键值和dotnetfx.exe的版本和语言设置。
hklm\software\microsoft\.netframework\policy\v1.0
3.如果需要安装.net framework, 在全局函数execcmd()中调用下面的命令silent安装dotnetfx.exe: dotnetfx.exe /q:a /c:"install /l /q"
4.在execcmd()全局函数中调用下面的命令安装您自己的msi文件:msiexec /i reboot=reallysuppress
使用方法
如果我们使用上面的native代码作为自己的安装程序,那么我们可以通过下面的步骤把自己的.net程序和它结合在一起:
1.把您自己的.net程序制作成为windows installer (.msi)文件。
2.打开"settings.ini"文件,在"msi" key中设置您自己的.net程序的msi文件路径和文件名;在"fxinstallerpath" key中,设置dotnetfx.exe的路径。具体的参数信息,您可以从下面文章中得到:
http://msdn.microsoft.com/librar ... /redisspaneploy.asp
3. 把"setup.exe", "settings.ini", "dotnetfx.exe"和您自己的msi安装文件,发送到目标机器上,然后运行"setup.exe", 安装程序会自动检测是否有.net framwork, 如果没有,将首先运行dotnetfx.exe。
总结
通过上述步骤,您可以将自己的.net程序成功的部署到没有安装.net framwork环境的机器上。 |
|