简体   繁体   English

AssemblyInfo.cs subversion和TortoiseSVN

[英]AssemblyInfo.cs subversion and TortoiseSVN

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? 我正在使用TortoiseSVN和Visual Studio 2008.有没有办法在每个版本中用svn的版本更新我的项目的assemblyinfo.cs?

For example, 1.0.0.[svn's version] -> 1.0.0.12 例如,1.0.0。[svn的版本] - > 1.0.0.12

You could use the SubWCRev tool which comes with TortoiseSVN (also available separately). 您可以使用TortoiseSVN附带的SubWCRev工具(也可单独购买)。

Either run it from a command line or use the COM-Object it offers. 从命令行运行它或使用它提供的COM-Object

The SubWCRev command line tool replaces keywords inside a file with information from your svn working copy. SubWCRev命令行工具使用 svn工作副本中的信息替换文件中的关键字 An example is shown in the docs. 文档中显示了一个示例

I do this in my build script : 我在构建脚本中执行此操作:

<SvnInfo LocalPath=".">
  <Output TaskParameter="Revision" PropertyName="BuildRev" />
</SvnInfo>
<FileUpdate Files="protobuf-net\Properties\AssemblyInfo.cs"
  Regex='(\[\s*assembly:\s*AssemblyVersion\(\s*"[^\.]+\.[^\.]+)\.([^\.]+)(\.)([^\.]+)("\)\s*\])'
  ReplacementText='$1.$2.$(BuildRev)$5' />

using the community build tasks . 使用社区构建任务 This essentially applies a regex to the AssemblyInfo.cs, replacing the current revision with the svn revision. 这基本上将正则表达式应用于AssemblyInfo.cs,用svn修订版替换当前版本。

You could use the $Rev$ svn keyword but that will give you the last revision of the file, I think you want to get the HEAD revision number. 您可以使用$Rev$ svn关键字,但这将为您提供该文件的最新修订,我想您想获得HEAD修订版号。

Give a look to this question: 看看这个问题:

您对Visual Studio 插件的感觉如何?

Yes, you can add a pre-build event that calls a script which 是的,您可以添加一个调用脚本的预构建事件

  • calls 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 ); 调用svn info来提取当前的版本号(如果你之前做过更新,你可以直接在文件中包含关键字$Revision$ ,也可以查看这篇文章 );
  • modifes your Properties\\AssemblyInfo.cs file accordingly. 相应地修改您的Properties \\ AssemblyInfo.cs文件。

What I usually do is transform a AssemblyInfo.cs template when the project is built. 我通常做的是在构建项目时转换AssemblyInfo.cs模板。 The script is necessary to adapt the form of $Revision$ to the syntax of this file, unfortunately. 不幸的是,该脚本是必要的,以使$ Revision $的形式适应该文件的语法。

The interesting properties are (where the template strings are between '$'): 有趣的属性是(模板字符串在'$'之间):

[assembly: AssemblyVersion("$v$.$build$.$Last Changed Rev$")]
[assembly: AssemblyFileVersion("$v$.$build$.$Last Changed Rev$")]

Edit: svn info is part of the standard SVN client, not TortoiseSVN as pointed out in another post. 编辑: svn info是标准SVN客户端的一部分,而不是另一篇文章中指出的TortoiseSVN。 Easy to install though. 虽然易于安装。 However, TortoiseSVN comes with SubWCRev.exe which transforms a file with keyword substitution, so it would do the trick if you update your local copy. 但是,TortoiseSVN附带SubWCRev.exe ,它会使用关键字替换来转换文件,因此如果您更新本地副本,它将会起作用。

In Visual Studio 2008, you can define a pre-build event that can launch a script or small program. 在Visual Studio 2008中,您可以定义可以启动脚本或小程序的预构建事件。 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. 在此脚本或程序中,您可以使用svnversion命令获取存储库修订,然后解析AssemblyInfo.cs并将版本号修改为您想要的版本号。

I'm not sure if TortoiseSVN comes with svnversion, but it does come with the Windows SVN build provided by CollabNet 我不确定TortoiseSVN是否带有svnversion,但它确实附带了CollabNet提供Windows SVN构建

I created an SVN version plug-in for the Build Version Increment project (which is named in popester's answer). 我为Build Version Increment项目创建了一个SVN版本插件 (以popester的答案命名)。 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. 此SVN插件将从您的工作副本中提取最新的更改修订版号,并允许您在版本号中使用该编号,这应该完全符合您的要求。

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

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