public VersionStruct(VersionStruct v) { Major = v.Major; Minor = v.Minor; BuildString = v.BuildString; Revision = v.Revision; }
public static VersionStruct Parse(string content) { var result = new VersionStruct(); var tokens = content.Split('.'); if (tokens.Length < 2) { throw new Exception("Unsupported version struct format"); } int tmp = 0; if (!int.TryParse(tokens[0], out tmp)) { throw new Exception($"Not valid major format: {tokens[0]}"); } result.Major = tmp; if (!int.TryParse(tokens[1], out tmp)) { throw new Exception($"Not valid minor format: {tokens[1]}"); } result.Minor = tmp; if (tokens.Length == 3) { if (tokens[2] == "*") { result.BuildString = tokens[2]; return(result); } if (!int.TryParse(tokens[2], out tmp)) { throw new Exception($"Not valid build format: {tokens[2]}"); } result.BuildInt = tmp; } else if (tokens.Length == 4) { if (tokens[2] == "*") { throw new Exception("Version format cannot contain revision when build is \"*\""); } if (!int.TryParse(tokens[2], out tmp)) { throw new Exception($"Not valid build format: {tokens[2]}"); } result.BuildInt = tmp; if (!int.TryParse(tokens[3], out tmp)) { throw new Exception($"Not valid revision format: {tokens[3]}"); } result.Revision = tmp; } return(result); }
static (VersionStruct assembly, VersionStruct file) GetVersionFromAssemblyInfo(string content) { VersionStruct assembly = null; VersionStruct file = null; Regex reg = new Regex("\".*\""); foreach (var line in content.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries)) { if (line.Contains("AssemblyVersion")) { string c = reg.Match(line).Value.Trim('"'); assembly = VersionStruct.Parse(c); } if (line.Contains("AssemblyFileVersion")) { string c = reg.Match(line).Value.Trim('"'); file = VersionStruct.Parse(c); } } return(assembly, file); }