You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

53 line
2.1 KiB

  1. using System.IO;
  2. using System.Xml;
  3. using FlubuCore.Context;
  4. using FlubuCore.Scripting.Attributes;
  5. namespace BuildScript
  6. {
  7. [Reference("System.Xml.XmlDocument, System.Xml, Version=4.0.0.0, Culture=neutral, publicKeyToken=b77a5c561934e089")]
  8. public partial class BuildScript
  9. {
  10. public BuildVersion FetchBuildVersion(ITaskContext context)
  11. {
  12. var content = File.ReadAllText(RootDirectory.CombineWith("build/version.props"));
  13. XmlDocument doc = new XmlDocument();
  14. doc.LoadXml(content);
  15. var versionMajor = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionMajor").InnerText;
  16. var versionMinor = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionMinor").InnerText;
  17. var versionPatch = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionPatch").InnerText;
  18. var versionQuality = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionQuality").InnerText;
  19. versionQuality = string.IsNullOrWhiteSpace(versionQuality) ? null : versionQuality;
  20. var suffix = versionQuality;
  21. bool isCi = false;
  22. bool isTagged = false;
  23. if (!context.BuildServers().IsLocalBuild)
  24. {
  25. isCi = true;
  26. bool isTagAppveyor = context.BuildServers().AppVeyor().IsTag;
  27. if (context.BuildServers().RunningOn == BuildServerType.AppVeyor && isTagAppveyor ||
  28. context.BuildServers().RunningOn == BuildServerType.TravisCI && string.IsNullOrWhiteSpace(context.BuildServers().Travis().TagName))
  29. {
  30. isTagged = true;
  31. }
  32. }
  33. if (!isTagged)
  34. {
  35. suffix += (isCi ? "preview-" : "dv-") + CreateStamp();
  36. }
  37. suffix = string.IsNullOrWhiteSpace(suffix) ? null : suffix;
  38. var version = new BuildVersion(int.Parse(versionMajor), int.Parse(versionMinor), int.Parse(versionPatch), versionQuality);
  39. version.Suffix = suffix;
  40. return version;
  41. }
  42. }
  43. }