简体   繁体   English

在编译时在Windows应用程序中嵌入SVN修订版号

[英]Embedding SVN Revision number at compile time in a Windows app

I'd like my .exe to have access to a resource string with my svn version. 我希望我的.exe能够访问我的svn版本的资源字符串。 I can type this in by hand, but I'd prefer an automated way to embed this at compile time. 我可以手动输入,但我更喜欢在编译时自动嵌入它。 Is there any such capability in Visual Studio 2008? Visual Studio 2008中是否有这样的功能?

I wanted a similar availability and found $Rev$ to be insufficient because it was only updated for a file if that file's revision was changed (which meant it would have to be edited and committed very time: not something I wanted to do.) Instead, I wanted something that was based on the repository's revision number. 我想要一个类似的可用性,发现$ Rev $是不够的,因为只有当文件的修订版被更改时才更新文件(这意味着它必须经过编辑和提交时间:不是我想做的事情。) ,我想要一些基于存储库版本号的东西。

For the project I'm working on now, I wrote a Perl script that runs svnversion -n from the top-most directory of my working copy and outputs the most recent revision information to a .h file (I actually compare it to a saved reversion in a non-versioned file in my working copy so that I'm not overwriting current revision information at every compile but whether you chose to do so is up to you.) This .h file (or a number of files if necessary, depending on your approach) is referenced both in my application code and in the resource files to get the information where I'd like it. 对于我现在正在处理的项目,我编写了一个Perl脚本,它从我工作副本的最顶层目录运行svnversion -n ,并将最新的修订信息输出到.h文件(实际上我将它与保存的文件进行比较)在我的工作副本中的非版本化文件中进行恢复,这样我就不会在每次编译时覆盖当前的修订信息,但是你是否选择这样做取决于你。)这个.h文件(或者如果需要的话,还有很多文件,取决于您的方法)在我的应用程序代码和资源文件中都被引用,以获取我喜欢的信息。

This script is run as a pre-build step so that everything is up-to-date before the build kicks off and the appropriate files are automatically rebuilt by your build tool. 此脚本作为预构建步骤运行,以便在构建开始之前一切都是最新的,并且构建工具会自动重建相应的文件。

How about using SubWCRev the command line tool that ships with TortoiseSVN . 如何使用TortoiseSVN附带的命令行工具SubWCRev You create a template file with tokens in it like $WCREV$ $WCDATE$ etc. Then have a pre-build step that run SubWCRev on your template file to create the actual source file that is fed to the compiler. 您可以在其中创建一个包含令牌的模板文件,如$ WCREV $ $ WCDATE $等。然后在模板文件上运行SubWCRev的预构建步骤,以创建提供给编译器的实际源文件。

You can get SVN to embed it for you , if that will solve the problem. 如果可以解决问题,您可以让SVN为您嵌入它 See the $Rev$ keyword on that page. 请参阅该页面上的$ Rev $关键字。

Have a look at svn keyword substitution here . 这里看一下svn关键字替换。 There is another SO question here which I found through google! 还有一种太问题在这里 ,我通过谷歌找到了!

antik's solution is the one we use. antik的解决方案是我们使用的解决方案。 Be careful of using environment variables, the .h file ensures you can have a dependency which will cause any files that need it to be recompiled when the svn rev number changes. 小心使用环境变量,.h文件确保您可以具有依赖性,这将导致在svn rev编号更改时重新编译需要它的任何文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM