Created
July 18, 2016 13:06
-
-
Save bezzad/7d44abf0465d790c3cc87341cef8980d to your computer and use it in GitHub Desktop.
Auto .net project version updater by TextTemplete (.tt)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#@ template language="C#" hostspecific="true" #> | |
<#@ import namespace="System.IO" #> | |
<#@ import namespace="System.Text.RegularExpressions" #> | |
<#@ output extension=".txt" #> | |
//------------------------------------------------------------------------------ | |
// <auto-generated> | |
// This code was generated by a tool. | |
// Runtime Version:4.0.30319.42000 | |
// | |
// Changes to this file may cause incorrect behavior and will be lost if | |
// the code is regenerated. | |
// | |
// This file is a T4 Text Templete for change automatically this | |
// project files version. | |
// | |
// Affected files: | |
// | |
// 1. Assembly Version | |
// </auto-generated> | |
//------------------------------------------------------------------------------ | |
<# | |
string path = Host.ResolvePath(".."); | |
var AssemblyFilePath = Path.Combine(path, "Properties\\AssemblyInfo.cs"); | |
//========================================== Assembly File ================================================== | |
string newVersion = null; | |
if(File.Exists(AssemblyFilePath)) | |
{ | |
var AssemblyFileData = File.ReadAllText(AssemblyFilePath); | |
var asmVerPattern = @"(\[assembly: [\w\.]*Version\("")(?<asmVer>[\d+\.\d+]*)(""\)\])"; | |
var match = Regex.Match(AssemblyFileData, asmVerPattern); | |
var gAsmVer = match.Groups["asmVer"].Value; | |
var oldVersion = new Version(gAsmVer); | |
// Compile new version [major.minor.build] = 2.4.99 | |
if (oldVersion.Build >= 99) | |
{ | |
newVersion = oldVersion.Minor >= 99 | |
? new Version(oldVersion.Major + 1, 0, 0).ToString() | |
: new Version(oldVersion.Major, oldVersion.Minor + 1, 0).ToString(); | |
} | |
else | |
{ | |
newVersion = new Version(oldVersion.Major, oldVersion.Minor, oldVersion.Build + 1).ToString(); | |
} | |
// | |
// Set new version in target files | |
AssemblyFileData = Regex.Replace(AssemblyFileData, asmVerPattern, m => m.Groups[1].Value + newVersion + m.Groups[2].Value); | |
File.WriteAllText(AssemblyFilePath, AssemblyFileData); | |
} | |
//========================================== Assembly File ================================================== | |
//=========================================================================================================== | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment