public
Last active

Update android version strings

  • Download Gist
AndroidAutoIncrementVersion.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
using System.IO;
using System.Text.RegularExpressions;
 
namespace AndroidAutoIncrementVersion
{
class Program
{
static void Main(string[] args)
{
try
{
string file = @"AndroidManifest.xml";
string text = File.ReadAllText(file);
Regex regex = new Regex(@"(?<A>android:versionCode="")(?<VER>\d+)(?<B>"")", RegexOptions.IgnoreCase);
Match match = regex.Match(text);
int verCode = int.Parse(match.Groups["VER"].Value) + 1;
text = regex.Replace(text, "${A}" + verCode + "${B}", 1);
 
Regex regex1 = new Regex(@"(?<A>android:versionName=""\d+\.\d+\.)(?<VER>\d+)(?<B>"")", RegexOptions.IgnoreCase);
Match match1 = regex1.Match(text);
int verCode1 = int.Parse(match1.Groups["VER"].Value) + 1;
text = regex1.Replace(text, "${A}" + verCode1 + "${B}", 1);
 
File.WriteAllText(file, text);
}
catch {}
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.