コード例 #1
0
ファイル: VersionService.cs プロジェクト: devlead/Aero
        private void UpdateCsProjFile(FilePath filePath, string version)
        {
            if (!CakeContext.XmlPeek(filePath, "/Project/@Sdk").StartsWith("Microsoft.NET.Sdk"))
            {
                return;
            }

            const string semver = @"^(\d+\.\d+\.\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$";
            var          regex  = new Regex(semver);
            var          match  = regex.Match(version);

            if (match.Success)
            {
                version = string.IsNullOrWhiteSpace(match.Groups[3].Value) ? match.Groups[1].Value : $"{match.Groups[1]}.{match.Groups[3]}";
            }
            else
            {
                //We either have Major.Minor.Build.Rev or yyMMdd.Rev from VSTS build
                //When we have yyMMdd.Rev, then we change it to yy.MM.dd.Rev
                var segments = version.Split('.');
                if (segments.Length == 2)
                {
                    version = $"{segments[0].Substring(0, 2)}.{segments[0].Substring(2, 2)}.{segments[0].Substring(4, 2)}.{segments[1]}";
                }
            }

            CakeContext.Information($"Update csproj for version. Version: {version}, File: {filePath}");
            CakeContext.XmlPoke(filePath, "/Project/PropertyGroup/AssemblyVersion", version);
            CakeContext.XmlPoke(filePath, "/Project/PropertyGroup/FileVersion", version);
            CakeContext.XmlPoke(filePath, "/Project/PropertyGroup/Version", version);
        }