Beispiel #1
0
        public override bool Execute( )
        {
            var     baseBuildVersionData = BuildVersionData.Load(BuildVersionXmlFile);
            CSemVer fullVersion          = baseBuildVersionData.CreateSemVer(IsAutomatedBuild, IsPullRequestBuild, BuildTimeStamp);

            SemVer              = fullVersion.ToString(true);
            NuGetVersion        = fullVersion.ToString(false);
            FileVersionMajor    = ( ushort )fullVersion.FileVersion.Major;
            FileVersionMinor    = ( ushort )fullVersion.FileVersion.Minor;
            FileVersionBuild    = ( ushort )fullVersion.FileVersion.Build;
            FileVersionRevision = ( ushort )fullVersion.FileVersion.Revision;

            ExtraProperties = (from kvp in baseBuildVersionData.AdditionalProperties
                               select new TaskItem("ExtraProperties", new Dictionary <string, string> {
                { "Name", kvp.Key }, { "Value", kvp.Value }
            })
                               ).ToArray( );

            return(true);
        }
Beispiel #2
0
        public static BuildVersionData Load(string path)
        {
            var retVal = new BuildVersionData( );

            using (var stream = File.OpenText(path))
            {
                var xdoc = System.Xml.Linq.XDocument.Load(stream, System.Xml.Linq.LoadOptions.None);
                var data = xdoc.Element("BuildVersionData");

                retVal.BuildVersionXmlFile = path;

                foreach (var attrib in data.Attributes())
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "BuildMajor":
                        retVal.BuildMajor = Convert.ToUInt16(attrib.Value);
                        break;

                    case "BuildMinor":
                        retVal.BuildMinor = Convert.ToUInt16(attrib.Value);
                        break;

                    case "BuildPatch":
                        retVal.BuildPatch = Convert.ToUInt16(attrib.Value);
                        break;

                    case "ReleaseBranch":
                        retVal.ReleaseBranch = attrib.Value;
                        break;

                    case "PreReleaseName":
                        retVal.PreReleaseName = attrib.Value;
                        break;

                    case "PreReleaseNumber":
                        retVal.PreReleaseNumber = Convert.ToByte(attrib.Value);
                        break;

                    case "PreReleaseFix":
                        retVal.PreReleaseFix = Convert.ToByte(attrib.Value);
                        break;

                    default:
                        retVal.ExtraPropertyMap.Add(attrib.Name.LocalName, attrib.Value);
                        break;
                    }
                }

                // correct malformed values
                if (string.IsNullOrWhiteSpace(retVal.PreReleaseName))
                {
                    retVal.PreReleaseNumber = 0;
                    retVal.PreReleaseFix    = 0;
                }

                if (retVal.PreReleaseNumber == 0)
                {
                    retVal.PreReleaseFix = 0;
                }
            }

            return(retVal);
        }