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.