I have a variables, which returns values from json:
$version = (Get-Content 'package.json' | ConvertFrom-Json).version
This value always goes in x.x.x format. It can be either 0.0.3 or 1.123.23 value.
My question is - how to increase the only patch value? E.g. I need to have 0.0.4 or 1.123.24 output values after transform.
Convert to a [version]
object:
# read existing version
$version = [version](Get-Content 'package.json' | ConvertFrom-Json).version
# create new version based on previous with Build+1
$bumpedVersion = [version]::new($version.Major, $version.Minor, $Version.Build + 1)
Alternatively, split the string manually:
$major,$minor,$build = $version.Split('.')
# increment build number
$build = 1 + $build
# stitch back together
$bumpedVersion = $major,$minor,$build -join '.'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With