AssemblyInfo.cs 颠覆和 TortoiseSVN
我正在使用 TortoiseSVN 和 Visual Studio 2008。 有没有办法在每个构建中使用 svn 的版本更新我的项目的 assemblyinfo.cs ?
例如,1.0.0.[svn 的版本] -> 1.0.0.12
I'm using TortoiseSVN and Visual Studio 2008.
Is there any way to update my project's assemblyinfo.cs with svn's version in every build?
For example, 1.0.0.[svn's version] -> 1.0.0.12
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以使用 TortoiseSVN 附带的 SubWCRev 工具(也可单独购买) 。
从命令行运行它或使用 COM-Object 它提供。
SubWCRev 命令行工具用以下信息替换文件内的关键字你的 svn 工作副本。文档中显示了示例。
You could use the SubWCRev tool which comes with TortoiseSVN (also available separately).
Either run it from a command line or use the COM-Object it offers.
The SubWCRev command line tool replaces keywords inside a file with information from your svn working copy. An example is shown in the docs.
我在我的构建脚本中执行此操作:
使用社区构建任务。这实质上将正则表达式应用于 AssemblyInfo.cs,用 svn 修订版替换当前修订版。
I do this in my build script:
using the community build tasks. This essentially applies a regex to the AssemblyInfo.cs, replacing the current revision with the svn revision.
您可以使用
$Rev$
svn 关键字 但这将为您提供文件的最后修订版本,我认为您想要获取HEAD
修订号。看看这个问题:
You could use the
$Rev$
svn keyword but that will give you the last revision of the file, I think you want to get theHEAD
revision number.Give a look to this question:
您对 Visual Studio 插件 执行此操作有何看法?
How do you feel about a Visual Studio addin doing it?
是的,您可以添加一个预构建事件,该事件调用一个脚本,该脚本
svn info
来提取当前修订号(如果您之前进行过更新,则可以直接包含关键字$Revision $
在文件中,还检查 这篇文章);我通常做的是在构建项目时转换 AssemblyInfo.cs 模板。不幸的是,该脚本必须使 $Revision$ 的形式适应该文件的语法。
有趣的属性是(模板字符串位于“$”之间):
编辑:
svn info
是标准 SVN 客户端的一部分,而不是另一篇文章中指出的 TortoiseSVN。不过安装很容易。然而,TortoiseSVN 附带了SubWCRev.exe
,它可以通过关键字替换来转换文件,因此如果您更新本地副本,它就会起作用。Yes, you can add a pre-build event that calls a script which
svn info
to extract the current revision number (if you do an update before, you can directly include the keyword$Revision$
in a file, check also this post);What I usually do is transform a AssemblyInfo.cs template when the project is built. The script is necessary to adapt the form of $Revision$ to the syntax of this file, unfortunately.
The interesting properties are (where the template strings are between '$'):
Edit:
svn info
is part of the standard SVN client, not TortoiseSVN as pointed out in another post. Easy to install though. However, TortoiseSVN comes withSubWCRev.exe
which transforms a file with keyword substitution, so it would do the trick if you update your local copy.在 Visual Studio 2008 中,您可以定义可启动脚本或小程序的预构建事件。在此脚本或程序中,您可以使用svnversion命令获取存储库修订版,然后解析您的AssemblyInfo.cs并将版本号修改为您想要的版本号。
我不确定 TortoiseSVN 是否附带 svnversion,但它确实附带提供的 Windows SVN 版本通过 CollabNet
In Visual Studio 2008, you can define a pre-build event that can launch a script or small program. Within this script or program, you can use the svnversion command to get the repository revision, then parse your AssemblyInfo.cs and modify the version number to what you desire.
I'm not sure if TortoiseSVN comes with svnversion, but it does come with the Windows SVN build provided by CollabNet
我为 SVN 版本插件创建了一个。 com/" rel="nofollow noreferrer">构建版本增量项目(在 popester 的答案中命名)。此 SVN 插件将从您的工作副本中提取最新的更改修订号,并允许您在版本号中使用它,这应该完全完成您想要做的事情。
I created an SVN version plug-in for the Build Version Increment project (which is named in popester's answer). This SVN plug-in will pull the latest change revision number from your working copy and allow you to use that in your version number, which should accomplish exactly what you're trying to do.