AssemblyInfo.cs subversion and TortoiseSVN

故事扮演 提交于 2019-11-28 21:18:54

问题


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


回答1:


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.




回答2:


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.




回答3:


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 I sync the SVN revision number with my ASP.NET web site?



回答4:


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




回答5:


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.




回答6:


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




回答7:


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.



来源:https://stackoverflow.com/questions/1621663/assemblyinfo-cs-subversion-and-tortoisesvn

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