在编译时在 Windows 应用程序中嵌入 SVN 修订号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/151299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Embedding SVN Revision number at compile time in a Windows app
提问by Gordon Wilson
I'd like my .exe to have access to a resource string with my svn version. 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?
我希望我的 .exe 可以使用我的 svn 版本访问资源字符串。我可以手动输入它,但我更喜欢在编译时以自动方式嵌入它。Visual Studio 2008 中是否有这样的功能?
回答by antik
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.
此脚本作为预构建步骤运行,以便在构建开始之前一切都是最新的,并且您的构建工具会自动重建相应的文件。
回答by Rodney Schuler
How about using SubWCRevthe command line tool that ships with TortoiseSVN. 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.
如何使用SubWCRev随TortoiseSVN附带的命令行工具。您创建一个包含令牌的模板文件,例如 $WCREV$ $WCDATE$ 等。然后有一个预构建步骤,在您的模板文件上运行 SubWCRev 以创建提供给编译器的实际源文件。
回答by Adrian
You can get SVN to embed it for you, if that will solve the problem. See the $Rev$ keyword on that page.
如果可以解决问题,您可以让SVN 为您嵌入它。请参阅该页面上的 $Rev$ 关键字。
回答by Mike Thompson
回答by Matthew Smith
antik's solution is the one we use. 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.
antik 的解决方案是我们使用的解决方案。小心使用环境变量,.h 文件确保您可以拥有一个依赖项,这将导致在 svn rev 号更改时重新编译任何需要它的文件。