(MVC) MVC (2017 год)

The simplest way to create site's versioning (eng).

The simplest way to create site's versioning.

MS technology has a way to create versioning desktop application, for this solution MS provide file AssemblyInfo.vb, it use in compilation process of desktop application. But in web versioning more important, especially site has many zone (like developer, testing, production) and more than one programmer has right to update site in each zone. There are many way to create increment version of site by strong and hard external system used MSBuild and TFS, integrated with Jira, and more and more. But what is the simplest way? Is this way to create 10 string of code and use additionally only 5 seconds in day instead strong hard expensive external solution?

I have a answer to this question. And my solution takes into account versioning of site from GIT or SVN versioning. And this solution is really had approximately 10 string of code and additionally 5 second before publishing without hard expansive external systems. So, let look to the my solution.

First of all you need to create additionally console project. To prevent forgetting name of this project I add it to the main site project, like in screenshot below. This is not a new project and previous programmer has build it on ADO NET Typed DataSet (my extension of this project I build on Linq-to-SQL).



I don't link hardly this project to solution by tuning project dependency



because debugging of site will be lost main advantage of debugging - simple changing of code and refresh in browser. If additional project will be add hardly (with dependencies) to site solution, we are need to recompile and restart solution after each small changing of code. So, before each publishing site to hosting I going to this additional project and simple start this additional project.



This additional project creating simple .txt file in site directory.



Most advantage of my solution is not creating simple unrelated versioning number by increment integer value, therefore I read information about versioning from GIT repository.



But GIT repository is not important for this idea. I have many-many long time project, and each of it used another repository system. For example my long-time project https://arenda.votpusk.ru/default.aspx use SVN repository.



Gift project has only 39 commit version, but Arenda project has 438 committed site version, and in Gift project I use local repository (because I working now in this project just only one), opposite of one Arenda project has SVN repository in web-server, and I'm working of that project not only one. But common idea is the same, reading information from repository system and showing it in special page on site. To read and showing this text file I use different way, for example in Arenda project I have special control, but in Gift project I use simple literal.



...
  66:      <div class="row">
  67:          <div class="col-md-5 col-md-offset-3 setting-gf">
  68:               <div class="body-login">
  69:                   <h1 class="text-center">Site version</h1>
  70:                   <asp:Literal ID="VersionLiteral" runat="server" />
  71:               </div>  
  72:            </div>
  73:       </div>
...

...
  18:              If My.Computer.FileSystem.FileExists(IO.Path.Combine(Server.MapPath("~"), "version.txt")) Then
  19:                  Dim VersionInfo As String = My.Computer.FileSystem.ReadAllText(IO.Path.Combine(Server.MapPath("~"), "version.txt"))
  20:                  Dim RDR1 = New IO.StringReader(VersionInfo)
  21:                  VersionLiteral.Text = "<table border='0'>"
  22:                  For i As Integer = 0 To 6
  23:                      Dim One As String = RDR1.ReadLine
  24:                      Dim Arr1() As String = One.Split("#")
  25:                      VersionLiteral.Text = VersionLiteral.Text & "<tr><td>" & Arr1(0) & "&nbsp;&nbsp;</td><td>" & "<span style='color:red'>" & Arr1(1).Replace("<", "&lt;").Replace(">", "&gt;") & "</span></td></tr>"
  26:                  Next
  27:                  VersionLiteral.Text = VersionLiteral.Text & "</table>"
  28:              End If
...

So, if you understanding my common idea, let's look to small project to getting information from Repository system. It's a extremely simple console application - one class.


   1:  Public Class GitRepository
   2:      Implements IDisposable
   3:   
   4:      Private ReadOnly _gitProcess As Process
   5:   
   6:      Public Sub New(path As String)
   7:          Dim processInfo = New ProcessStartInfo() With {
   8:                  .UseShellExecute = False,
   9:                  .RedirectStandardOutput = True,
  10:                  .FileName = "git.exe",
  11:                  .CreateNoWindow = True,
  12:                  .WorkingDirectory = If((path IsNot Nothing AndAlso IO.Directory.Exists(path)), path, Environment.CurrentDirectory)
  13:          }
  14:   
  15:          _gitProcess = New Process()
  16:          _gitProcess.StartInfo = processInfo
  17:      End Sub
  18:   
  19:      Public Function RunCommand(args As String) As String
  20:          _gitProcess.StartInfo.Arguments = args
  21:          _gitProcess.Start()
  22:          Dim output As String = _gitProcess.StandardOutput.ReadToEnd().Trim()
  23:          _gitProcess.WaitForExit()
  24:          Return output
  25:      End Function
  26:   
  27:   
  28:      Public Sub Dispose()
  29:          If Not _disposed Then
  30:              _disposed = True
  31:              _gitProcess.Dispose()
  32:          End If
  33:      End Sub
  34:   
  35:   
  36:      Private Sub IDisposable_Dispose() Implements IDisposable.Dispose
  37:          Throw New NotImplementedException()
  38:      End Sub
  39:   
  40:      Private _disposed As Boolean
  41:   
  42:  End Class

And one module.


   1:  Module Module1
   2:   
   3:      Sub Main()
   4:          Dim PRM() As String = Environment.GetCommandLineArgs
   5:          If PRM.Count < 3 Then
   6:              Console.WriteLine("Usage: Read GIT repository from 'PRM(1)' And Write info to 'PRM(2)'")
   7:              Exit Sub
   8:          End If
   9:          Console.WriteLine("Read GIT repository from " & PRM(1) & " And Write info to " & PRM(2))
  10:          Dim Res1 As New Text.StringBuilder
  11:          Res1.AppendLine("GitRepository#" & PRM(1))
  12:          Res1.AppendLine("SiteBuildDate#" & Now.ToString("yyyy-MM-dd HH:mm:ss"))
  13:          Try
  14:              Dim Git = New GitRepository(PRM(1)) '= New GitRepository("F:\Projects\test-giftrepublic")
  15:   
  16:              Dim Query1 As String = Git.RunCommand("rev-list --all --count")
  17:              'Return:
  18:              '2
  19:              If Query1 <> "" Then
  20:                  Res1.AppendLine("Version#" & CInt(Query1))
  21:              End If
  22:   
  23:              Dim Query2 As String = Git.RunCommand("log -1")
  24:              'Return:
  25:              'commit 1aa1d4f20bbfaeae4c7844d65112119f68394e4d
  26:              'Author: belgorod275 <[email protected]>
  27:              'Date:   Sat Nov 11 02:44:07 2017 +0300
  28:              '
  29:              'Add project files.
  30:              '
  31:              If Query2 <> "" Then
  32:                  Dim RDR1 = New IO.StringReader(Query2)
  33:                  For i As Integer = 0 To 4
  34:                      Dim One As String = RDR1.ReadLine
  35:                      Dim Arr1() As String = One.Split(":")
  36:                      If Arr1.Count > 1 Then
  37:                          If Arr1(0) = "Author" Then
  38:                              Res1.AppendLine("CommitAuthor#" & Arr1(1).Trim)
  39:                          ElseIf Arr1(0) = "Date" Then
  40:                              Res1.AppendLine("CommitDate#" & One.Replace("Date:", "").Trim)
  41:                          End If
  42:                      ElseIf i = 0 And One.Length > 0 Then
  43:                          Dim Arr2() As String = One.Split(" ")
  44:                          Res1.AppendLine("CommitHash#" & Arr2(1).Trim)
  45:                      ElseIf i > 0 And One.Length > 0 Then
  46:                          Res1.AppendLine("CommitInfo#" & One.Trim)
  47:                      End If
  48:                  Next
  49:              End If
  50:          Catch ex As Exception
  51:              Res1.AppendLine("Error#" & ex.Message)
  52:          End Try
  53:          Console.WriteLine(Res1.ToString)
  54:          'Console.ReadLine()
  55:          My.Computer.FileSystem.WriteAllText(PRM(2), Res1.ToString, False)
  56:          'Result:
  57:          'GitRepository#F:\Projects\test-giftrepublic
  58:          'SiteBuildDate#2017-11-11 12:59:58
  59:          'Version#39
  60:          'CommitHash#c7588d551fb710251f754fd101d3705dfbfa9a76
  61:          'Author#khark <khark@DESKTOP-UM8SJPN>
  62:          'CommitDate#Sat Nov 11 00:41:33 2017 +0300
  63:          'CommitInfo#Amended order Id And Message issues
  64:      End Sub
  65:  End Module

You need to understand tat we are said only about creating and showing version of site, to prevent confusion with version in many site zone, but this is not a solution of creation relation of database version of site and code version of site. Structure of database usually update independently of code, and for full correct solution you need to showing not only code version, but you need to show database structure version. But this is another question, some my opinion of this questions you may see in another topic Comparison of freeware Compare SQL-Database tools (in Ukrainian ang).





Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: //www.vb-net.com/SiteVersioning/index.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>