Customizing version control with PowerShell

Source: Internet
Author: User
Tags command line reflection

Here's just one of my little ideas, in large projects, we're used to compiling our systems in a command line style, such as compiling a. NET program with Nant, but I'm thinking that if you build it once, the version number plus 1 is fine, not the. NET itself. With that addition, I came up with a small script that uses PowerShell to define a version control, as follows:

$ver="ver.cs"

$s=[System.IO.File]::ReadAllLines($ver)

if($s.Length - eq 2){

      $num=$s[1].Remove(0, 28).Remove(7, 3).Split('.')

      $sum=$num[0]+$num[1]+$num[2]+$num[3]

      $result=$sum -as [Int32]     

      $r=$result+1

      $results=$r.ToString();

      write-host Current Version: $results

      $build="[assembly: AssemblyVersion ("""
              +$results[0]+"."
              +$results[1]+"."
              +$results[2]+"."

               +$results[3]+""")]"

      $s="using System.Reflection;",$build

      [System.IO.File]::WriteAllLines($ver,$s)   

}

Where Ver.cs is a C # file with only version-controlled code:

using System.Reflection;
[assembly: AssemblyVersion("1.0.0.0")]

Then, in the batch of your build, execute this script, and the 1.0.0.0 in Ver.cs will automatically add 10% to 1.0.0.1, and of course, the script can be arbitrarily changed so you can define the version you want to automatically grow.

Welcome to the brick, if you have your own version control mode, you can share under. This is just my own creativity, I think it is not the best, so when the start ...

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.