svn如何退回软件版本_在应用程序版本中使用svn修订版本号

In a VS2010 solution (not .NET), I'm looking to include the svn revision number as part of the application version.

we do not use makefiles at the moment, only the VS solution/project settings.

I'd like to get the working copy revision number at compile time, store it into a variable, so it can be used later on in the code to display the version number.

So far, I've successfully used svnversion to get the latest version of the working copy as a pre-built event.

"C:\Program Files\CollabNet\Subversion Client\svnversion.exe" -n $(SolutionDir)

At build time, I can see the correct revision number being returned into the output console.

Now, the question is, how can store this value into a variable that can be used within the code?

I've tried defining a pre compiler variable (_SVNREV) and using it to save the result from the above cmd, directly from the pre-build event box, but that doesn't work.

_SVNREV="C:\Program Files\CollabNet\Subversion Client\svnversion.exe" -n $(SolutionDir)

%_SVNREV%="C:\Program Files\CollabNet\Subversion Client\svnversion.exe" -n $(SolutionDir)

%_SVNREV="C:\Program Files\CollabNet\Subversion Client\svnversion.exe" -n $(SolutionDir)

$(_SVNREV)="C:\Program Files\CollabNet\Subversion Client\svnversion.exe" -n $(SolutionDir)

none of these actually work.

RESOLUTION:

I was heading nowhere trying to update a variable from within the VS env. so I took another route, calling a script as a pre-build step, that gets the svn revision of the working copy and then creates a header file with that info.

Here's the svnrev.bat for anyone interested:

@echo off

set cmd="C:\"Program Files\CollabNet\Subversion Client"\svnversion.exe -n %1 "

set versionfile=%1/version.h

FOR /F %%i IN ('%cmd%') DO SET SVNVER=%%i

echo Detected program revision %SVNVER% in %1

echo #pragma once > %versionfile%

echo #define _SVNVER "%SVNVER%" >> %versionfile%

解决方案

the best guess i came up with so far is to generate a header file in the pre-build event that contains the svnversion.

e.g. i create a batch-script version.bat:

@echo off

FOR /F "tokens=*" %%i IN ('call svnversion') DO echo #define SVNVERSION "%%i" > svnversion.h

and wherever i want to get the svnversion, i simply #include "svnversion.h"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值