Windows下有没有办法自动生成svn版本号的命令,这样就不用每次都手工改代码生成版本号了。
离线
这是我的代码 prebuild.bat
rem ;;编译前预处理程序,生成svn版本与当前日期至version.h
rem ;;参考网址:
rem ;;http://stackoverflow.com/questions/203090/how-to-get-current-datetime-on-windows-command-line-in-a-suitable-format-for-us
rem ;;http://stackoverflow.com/questions/3179649/getting-the-current-revision-number-on-command-line-via-tortoisesvn
for /f "tokens=2" %%i in ('svn info -rHEAD ^|findstr "Revision"') do set svnversion=%%i
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
echo 工程配置: [%1]
echo 编译日期时间: [%ldt%]
echo 当前svn版本号: [%svnversion%]
echo #pragma once > version.h
echo #define SVN_VERSION %svnversion% >> version.h
echo #define PLATFORM_CONFIGURATION L"%1" >> version.h
echo #define BUILD_TIME L"%ldt%" >> version.h
生成的是这样:
#pragma once
#define SVN_VERSION 753
#define PLATFORM_CONFIGURATION L""
#define BUILD_TIME L"2018-03-09 16:14:21.380"
离线
谢谢, 借用这一句就可以了
for /f "tokens=2" %%i in ('svn info -rHEAD ^|findstr "Revision"') do set svnversion=%%i
离线