打包腳本的流程和自動(dòng)打包基本相同:
1. 編譯軟件
2. 拷貝需要的內(nèi)容
3. 代碼簽名
4. 打包成安裝文件
5. 再次簽名,并將安裝文件名稱改成需要的格式
------------------------------------------------------------------
編譯軟件需要初始化vs的運(yùn)行環(huán)境,如
call "D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
然后開編譯。
編譯完成,拷貝文件,使用signtool對(duì)軟件進(jìn)行簽名,
signtool sign /f codesign.cer ..\bin\app\Joywok.exe
最后將其修改為需要的命名風(fēng)格,這里使用了 git rev-list HEAD --count 來獲取git的提交次數(shù)作為build version
rem 修改軟件名稱
for /f "delims=" %%i in ('git rev-list HEAD --count') do (
set "buildversion=%%i"
)
echo %buildversion%
cd setup
set year=%date:~0,4%
set month=%date:~5,2%
set day=%date:~8,2%
set ymd=%year%%month%%day%-b%buildversion%
ren setup.exe joywok-aws-setup-%ymd%.exe
完整的示例:
@echo off
call "D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
rmdir /s/q ..\src\buildlib
mkdir ..\src\buildlib
cd ..\src\buildlib
qmake ..\JWLib_qt\JWLib_qt.pro -spec win32-msvc2013 "CONFIG-=debug" "CONFIG+=release force_debug_info" "DEFINES+=JW_AWS"
D:\Qt\qtcreator-4.2.1\bin\jom qmake_all
nmake -f Makefile.Release
rmdir /s/q ..\buildjoy
mkdir ..\buildjoy
cd ..\buildjoy
qmake ..\joywok_qt\joywok_qt.pro -spec win32-msvc2013 "CONFIG-=debug" "CONFIG+=release force_debug_info" "DEFINES+=JW_AWS"
D:\Qt\qtcreator-4.2.1\bin\jom qmake_all
nmake -f Makefile.Release
rem 拷貝文件并打包
cd ..\..\setup
del ..\bin\app\YWdatabase.db
rmdir /s/q ..\bin\app\cache
rmdir /s/q ..\bin\app\log
rmdir /s/q ..\bin\app\skin
rmdir /s/q ..\bin\app\qml
mkdir ..\bin\app\skin
mkdir ..\bin\app\qml
xcopy ..\bin\QDebug\skin\* ..\bin\app\skin /e
xcopy ..\bin\QDebug\qml\* ..\bin\app\qml /e
copy ..\lib\Release\JWLib_qt.dll ..\bin\app
copy ..\bin\Release\Joywok.exe ..\bin\app
rmdir /s/q ..\bin\app\crashes
set year=%date:~0,4%
set month=%date:~5,2%
set day=%date:~8,2%
set hour=%time:~0,2%
set minute=%time:~3,2%
set second=%time:~6,2%
set ymd=%year%%month%%day%_%hour%%minute%%second%
cd ..\crashlog
md "%ymd%"
copy /y ..\lib\Release\jwlib_qt.pdb "%ymd%"
copy /y ..\bin\Release\joywok.pdb "%ymd%"
copy /y ..\lib\Release\JWLib_qt.dll "%ymd%"
copy /y ..\bin\Release\Joywok.exe "%ymd%"
cd ..\setup
rem 簽名
signtool sign /f codesign.cer ..\bin\app\JWLib_qt.dll
signtool sign /f codesign.cer ..\bin\app\Joywok.exe
rem 打包
del app.7z
del setup.exe
..\software\7-Zip\7z.exe a -t7z app.7z ..\bin\app\*
..\software\NSIS\makensis.exe setup.nsi
signtool sign /f codesign.cer setup.exe
rem 修改軟件名稱
cd ..
for /f "delims=" %%i in ('git rev-list HEAD --count') do (
set "buildversion=%%i"
)
echo %buildversion%
cd setup
set year=%date:~0,4%
set month=%date:~5,2%
set day=%date:~8,2%
set ymd=%year%%month%%day%-b%buildversion%
ren setup.exe joywok-aws-setup-%ymd%.exe
pause
總結(jié)
以上所述是小編給大家介紹的Windows程序打包腳本[bat]的詳細(xì)流程,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!