在应用程序版本中使用svn修订版本号 [英] use svn revision number in application version

查看:882
本文介绍了在应用程序版本中使用svn修订版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VS2010解决方案(非.NET)中,我希望将svn修订版本号作为应用程序版本的一部分。

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

我们不使用makefiles目前只有VS解决方案/项目设置。

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.

到目前为止,我已经成功使用了 svnversion 以将最新版本的工作副本作为预构建事件

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?

我试过定义一个预编译器变量( _SVNREV ),并使用它直接从预构建事件框中保存上述cmd的结果,但不会工作。

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)

这些都不起作用。

RESOLUTION
我无法在VS env中更新变量。所以我采取了另一个路由,调用脚本作为预构建步骤,获取工作副本的svn修订版本,然后创建一个头文件与该信息。

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.

以下是任何感兴趣的人的 svnrev.bat

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%


推荐答案

far是在包含svnversion的预构建事件中生成头文件。

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

例如我创建一个批处理脚本 version.bat

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

和任何我想获得svnversion,我只是 includesvnversion.h

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

这篇关于在应用程序版本中使用svn修订版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆