Use the pre-generated event of Vs to obtain the SVN version as the internal version of the project.

Source: Internet
Author: User

Assemblyinfo. CS under properties in vs can set the corresponding version number. The following describes how to set the version of assemblyinfo. CS.

[assembly: AssemblyVersion("1.0.0.0")][assembly: AssemblyFileVersion("1.0.0.0")]
However, this needs to be set every time, and it is not consistent with the version number on SVN, it is not very convenient to catch up. So I want to use the SVN version number as the project version number. To obtain the SVN version number, you can use the svn command SVN info to obtain the information under the svn section. This can be easily achieved through the CMD command. However, I want to get it every time during vs compilation, so I chose to execute it in the vs pre-generated event command. View


Enter the CMD command in the pre-generated event command line.

1. SVN info> svn_info.txt is used to execute the svncommand, obtain the corresponding response information, and then save it to the svn_info.txt file.
2. findstr "revision" svn_info.txt> .. \ svn_version.dll search for the publication ID from svn_info.txt and coexist in svn_version.dll.
3. Delete the svn_info.txt file by del svn_info.txt.

Svn_version.dll will be generated during compilation. You need to add the file to the project so that it can be released at the same time. The name is svn_version.dll. You can find another name and suffix.

In this way, you can obtain the SVN version number by reading the content in svn_version.dll when the project is started.

String version = "1.1.1" string serverphysicalpath = server. mappath ("."); // on the web, you need to change the service path to the local path. If it is a winform program, you can obtain the program path. If (! Serverphysicalpath. endswith ("\") {serverphysicalpath + = "\";} string svnversionpath = serverphysicalpath + "svn_version.dll"; streamreader svnsteamreader = new streamreader (svnversionpath ); string line = svnsteamreader. readline (); If (! String. isnullorwhitespace (line) {string [] temps = line. split (':'); If (temps. length> 1) {version + = string. format (". {0} ", temps [1]) ;}} return version;
The above is done after saving SVN information into a file and then reading it. You can also directly write the SVN version information to assemblyinfo. CS and then obtain it.


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.