===== 需求来源=====
我们的驱动目前发布的有36支,每次发布前需要打开每个工程去修改产品版本,修改setup file name。修改脚本里的dll版本,重新编译,build工程。工作量很大,往往是已buid好后,有共用的dll文件又修改了bug,所有的工程需要重新buid。非常费时。
===== 需求实现:自动化编译 =====
Installsheild 提供了我们可以进行命令行编译的方法:
主要调用这个exe来实现:ISCmdBld.exe
下面是InstallShield 2010的帮助文档对ISCmdBld.exe的解释。
You can build a release from the command line using ISCmdBld.exe for Windows Installer–based projects and for InstallScript projects. If your project includes InstallScript, ISCmdBld.exe also compiles it before building the release.
Note:之前在网上有看到InstallShield 12 调用这个ISCmdBld.exe 去build的时候,不会complie,这两个动作是独立的,故你修改的脚本如果不在工程里编译,用命令行Build出得安装包里还是执行旧脚本的逻辑。但是InstallShield 2010在Build之前是会编译的。
==== 基本使用方法 ====
The following statement illustrates running ISCmdBld.exe to build the release Othello Beta:
ISCmdBld.exe -p "C:\InstallShield 2010 Projects\My Othello Project\Othello.ism" -r "Othello Beta" -c COMP -a "Build 245"
The first parameter in the example above,
-p, is the path to the .ism file that you would like to build.
-r "Othello Beta" is the name of the release.
-c COMP specifies that you would like your package to be compressed into one file.(UNCOMP)
-a "Build 245" points to the specific product configuration.
关于更多的参数,以及如何使用请在 InstallShield 2010 的帮助中搜索ISCmdBld.exe查看。
==== 实际应用====
我写的批处理来编译安装包的工程,例如PCI1710的安装包Build的批处理:
<code>::---------------------- batch file begin ----------------------------------------------
@ echo off
echo "****This is a batch file PCI1710.bat, that build a Release from the Command Line*****"
echo.
Set BUILD="D:\Program Files\InstallShield\2010\System\ISCmdBld.exe"
Set PACKAGE=-p "E:\AXA-VAULT\PackingProject\BionicDAQ\Windows\BioDAQ Driver\PCI1710\PCI1710.ism"
Set LOCATION=-b "E:\AXA-VAULT\PackingProject\BionicDAQ\Windows\Release\Informal\PCI1710"
Set CONFIGURATION=-a "Product Configuration 1"
Set RELEASE=-r "Release 1"
%BUILD% %PACKAGE% %LOCATION% %CONFIGURATION% %RELEASE%
exit
::----------------------- batch file end --------------------------------------------
但是每次发布去我们需要修改产品版本号,setup file name,我们的安装包还需要修改product code,通过命令行并不能修改这些参数,这样还要打开一个个的工程去修改了,怎么办?通过写VBScript的脚本来实现了这个功能。在脚本里设置工程的要修改的信息,然后调用批处理,即可自动编译出安装包。
' ----------------------------- Build.vbs begin -------------------------
call Build("PCI1710","PCI1710.ism" , "3.0.6.0", "Product Configuration 1", "DAQNavi_PCI1710_3.0.6.0")
call Build("PCI1711","PCI1711.ism" , "3.0.6.0", "Product Configuration 1", "DAQNavi_PCI1711_3.0.6.0")
Function Build(projectFolderName, projectName, productVersion, productConfig, setupFileName)
'Open project
Set pProject = CreateObject("ISWiAuto16.ISWiProject")
Dim projectPath
projectPath = "..\BioDAQ Driver\"+projectFolderName+"\"+projectName
pProject.OpenProject projectPath
' perform queries and changes here
' modify the gennaral info
pProject.ProductVersion = productVersion
pProject.ProductCode = pProject.GenerateGUID
' modify the product configuration
Dim pProdConfig
Set pProdConfig = pProject.ISWiProductConfigs.Item(productConfig)
pProdConfig.ProductVersion = productVersion
pProdConfig.SetupFileName = setupFileName
' necessary only if modifying the project
pProject.SaveProject
pProject.CloseProject
' Call the batch file to build the .ism file
Dim objShell
Set objShell = CreateObject("Wscript.Shell")
Dim batPath
batPath = "..\CompileBat\"+projectFolderName+".bat"
iReturn=objShell.Run("cmd.exe /C"+ batPath, 1, TRUE)
'Copy the file to the special folder
Set fso = WScript.CreateObject("scripting.filesystemobject")
Dim pathStr, SourcePath, targetPath
pathStr = fso.GetAbsolutePathName("..\Release\Informal")
SourcePath = pathStr +"\"+ projectFolderName +"\Product Configuration 1\Release 1\DiskImages\DISK1\"+setupFileName+".exe"
targetPath = fso.GetAbsolutePathName("..\Release\Formal")+"\"
fso.copyfile SourcePath, targetPath
End Function
' ----------------------------- Build.vbs end -----------------------------
Set pProject = CreateObject("ISWiAuto16.ISWiProject")
通过这条语句得到的pProject,工程里General标签下的项目以及添加删除Featrue, component等等都可以通过该变量去设置。更多的可以在installshield 2010 的帮助文档里搜索ISWiProject 可以看到可修改设置的东西很多。可根据工程需要在脚本里修改。
Set pProdConfig = pProject.ISWiProductConfigs.Item(productConfig)
ISWiProductConfig represents a product configuration in the Releases view of the InstallShield user interface.
productConfig该参数是 Product Configration的名字,通过这条语句得到的pProdConfig ,对应可设置工程里Releases 里 Product Configration下的可设置的项目。更多的可以在installshield 2010 的帮助文档里搜索ISWiProductConfigs可以看到可修改设置的东西很多。可根据工程需要在脚本里修改。
Set pRelease = pProdConfig.ISWiReleases.Item("Release1")
ISWiRelease represents a release in the InstallShield user interface.
"Release1"该参数是 Release的名字,通过这条语句得到的pRelease ,对应可设置工程里Releases 里 Product Configration下的 release 里可设置的项目。更多的可以在installshield 2010 的帮助文档里搜索ISWiReleases可以看到可修改设置的东西很多。可根据工程需要在脚本里修改。