Skip to content

Instantly share code, notes, and snippets.

@jgeurts
Created July 17, 2012 20:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jgeurts/3131675 to your computer and use it in GitHub Desktop.
Save jgeurts/3131675 to your computer and use it in GitHub Desktop.
Update android version strings
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 {}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment