AssemblyInfo.cs subversion and TortoiseSVN

后端 未结 7 969
情歌与酒
情歌与酒 2020-12-24 16:03

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\'

相关标签:
7条回答
  • 2020-12-24 16:09

    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.

    0 讨论(0)
  • 2020-12-24 16:09

    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.

    0 讨论(0)
  • 2020-12-24 16:19

    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.

    0 讨论(0)
  • 2020-12-24 16:21

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

    0 讨论(0)
  • 2020-12-24 16:22

    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?
    0 讨论(0)
  • 2020-12-24 16:28

    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.

    0 讨论(0)
提交回复
热议问题