mykeels.com

Bump csproj version with bash

A simple script to bump a csproj version using only bash scripting

Bump csproj version with bash

A simple script to bump a csproj version using only bash scripting.

When running on either main or master branches, the version is patch bumped with no suffix. e.g. 1.0.0 -> 1.0.1

For other branches, the version is patch bumped with an alpha suffix. e.g. 1.0.0 -> 1.0.1-alpha.1

# Get current version from csproj
VERSION=$(grep -oP '<Version>\K[^<]+' ./path/to/file.csproj)

IFS='.' read -r major minor patch <<< "$VERSION"
VERSION="$major.$minor.$((patch + 1))"
if [[ "${{ github.ref }}" == "refs/heads/main" || "${{ github.ref }}" == "refs/heads/master" ]]; then
    NEW_VERSION="${VERSION}"
else
    # For release branches, add alpha suffix
    NEW_VERSION="${VERSION}-alpha.${GITHUB_RUN_NUMBER}"
fi

Now, you can use the NEW_VERSION variable in your workflow.

Enjoy!

Bump csproj version with bash

Related Articles

Tags