AssemblyInfo.cs subversion and TortoiseSVN

此生再无相见时 提交于 2019-11-30 01:12:54

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.

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.

CMS

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.

Give a look to this question:

How do you feel about a Visual Studio addin doing it?

RedGlyph

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);
  • modifes your Properties\AssemblyInfo.cs file accordingly.

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 '$'):

[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. 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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!