Automatic Generation of the last digit of the assembly version using the SVN version number

Source: Internet
Author: User
Tags tortoisesvn
When using SVN for source code version control, we hope to quickly find each release The corresponding source code version can now be added by adding Svn in the assembly version information Source code version information to meet our requirements.

Now we define the version information of each Assembly Last segmentThe source code version of SVN. The detailed definition is as follows:

The Assembly version number is divided into four sections, for example, 1.0.4.23.

  1. The first section is the major version number. Project 1 will not be changed when started.
  2. The second paragraph is the minor version number, which is added when the project function is greatly adjusted. The increment is 1.
  3. The third section is the revision version number, which is usually added when fixing defects or minor functional changes, The increment is 1 or 2. The version number can be an odd or even number. An odd number indicates the test version.An even number indicates a stable version.
  4. The fourth section is the svn source code version, which is automatically generated by the script.
Prerequisites for using scripts to automatically generate SVN version:
  1. Install tortoisesvn;
  2. The source code is under SVN version management control.
Modify the project settings to automatically generate the version number:
  • Modify the properties/assemblyinfo. CS FileTo change the last section of the assembly version information to $ wcrev $. And add a line"// Last Release Date: $ wcdate $"
Example: [Assembly: assemblyversion ("1.1.0. $ wcrev $")]
[Assembly: assemblyfileversion ("1.1.0. $ wcrev $")] // last Release Date: $ wcdate $
  • Rename the assemblyinfo. CS file as assemblyin.Fo. TPL and add it to source code management.
  • Delete assemblyinfo. CS from the source code repository, exclude it, and make itNot Affected by version management.
  • Add generateassemblyinfo in this articleThe. BAT file is added to the properties directory and added to source code management.
  • Modify project properties inGenerate eventsOfPre-generated event command lineAdd the following command.

"$ (Projectdir)/Properties/Generateassemblyinfo. Bat "$ (projectdir)"./properties/assemblyinfo. TPL./properties/assemblyinfo. CS

Note::
  • In
    Before CompilationRemember to submit your changes and update others' changes so that the version number is correct.
  • To modify assembly information in the future, modify the assemblyinfo. TPL file.
  • If the generated assemblyinfo. CS file contains Chinese garbled characters, open assemblyinfo. TPL andFile->Advanced save optionsChange the file encodingUTF-8You can.

Script

Generateassemblyinfo. bat
::-----------------------------
: ** Initialize
@ Echo off
Setlocal enableextensions

Rem initialize Constants
Set tsvn_info_file =./tsvn_info.tmp

Rem initialize script arguments

Set workdir = % 1
Set template = % 2
Set target = % 3

Rem goto Main Entry
Goto main
:


::-----------------------------
: ** Main Entry
: Main
Pushd % workdir %
Set workdir = ./

Rem check parameters
If % workdir % = "" Goto argument_error
If % template % = "" Goto argument_error
If % target % = "" Goto argument_error

Rem Query registry
Reg query HKLM/software/tortoisesvn/V directory> % tsvn_info_file % 2> NUL

Rem searches for the tsvn path
For/F "tokens = *" % I in (% tsvn_info_file %) Do (
Echo % I | find "directory"> NUL
If % errorlevel % = 0 (
Echo % I> % tsvn_info_file %
)
)

Set/P tsvn_path = <% tsvn_info_file %
Set tsvn_path = % tsvn_path :~ 17,-1%.

Rem calls tsvn replacement Template
If not % errorlevel % = 0 goto unknow_error
"% Tsvn_path % bin/subwcrev.exe" % workdir % template % target %> NUL

If not % errorlevel % = 0 goto unknow_error
Goto sucessed
:


::-----------------------------
: ** Error handlers

: Argument_error
The parameter input by ECHO is invalid.
Goto fail

: Not_found_tsvn
Echo fails to query the installation information of tortoisesvn.
Goto fail

: Unknow_error
An unknown error occurs when ECHO generates assembly information.
: Fail
:

::-----------------------------
: ** Program exit
: Fail
Del/Q % tsvn_info_file % 2> NUL
An error occurred while generating assembly information by ECHO.
Popd
Exit 1

: Sucessed
Del/Q % tsvn_info_file % 2> NUL
Echo successfully generated the assembly information.
Popd
Exit 0
:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.