Skip to content

Instantly share code, notes, and snippets.

@vhoyer
Created April 13, 2018 11:42
Show Gist options
  • Save vhoyer/17f188871a0d0845c0d96660f3b01859 to your computer and use it in GitHub Desktop.
Save vhoyer/17f188871a0d0845c0d96660f3b01859 to your computer and use it in GitHub Desktop.
The variables are one char long due to my original limitations of the script lenght, sorry for that. the commentaries I added later
#Path to the AndroidManifest
$p="path\to\manifest\AndroidManifest.xml"
#Get the content of the file
$f=Get-Content $p
#Describe the pattern to search to edit the versionCode with RegEx
$r=@"
android:versionCode="\d+"
"@
#Get the part of the file's content that matches the RegEx
$v=[regex]::matches($f,$r).Value
#Take the part of interest (versionCode),
#search for any consecutive numbers as string and convert it to int
$v=[int]([regex]::matches($v,"\d+").Value)
#increment it
$v++
#Execute a
# foreach line of the original file's content
# search for the regex pattern
# substitute the original number with the new one
# save the new content to the "$c" variable
$c=$f|ForEach-Object{ $_ -replace $r, @"
android:versionCode="$v"
"@}
#Save the edited content to the original file
$c|Set-Content $p
#Print out the result for debbuging proposes
echo $c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment