private static string BumpVersion(string semver, Bumping which) { var parsed = ParseVersion(semver); if (parsed == null) { Logger.Warn($"[{semver}] is not a valid Semantic Versioning."); return(semver); } var(major, minor, patch) = parsed.GetValueOrDefault(); switch (which) { case Bumping.Major: major += 1; break; case Bumping.Minor: minor += 1; break; case Bumping.Patch: patch += 1; break; } return($"{major}.{minor}.{patch}"); }
public static bool BumpVersionForCsproj(string path, string currentSemver, Bumping which = Bumping.Patch) { var projContent = File.ReadAllText(path); var nextSemver = BumpVersion(currentSemver, which); var newCsprojContent = Regex.Replace(projContent, "<VersionPrefix>[0-9\\.]+</VersionPrefix>", $"<VersionPrefix>{nextSemver}</VersionPrefix>"); if (projContent == newCsprojContent) { return(false); } File.WriteAllText(path, newCsprojContent); return(true); }