protected override void OnTargetStart(string target) { if (VersionSuffix.IsNullOrEmpty() && !CustomVersionSuffix.IsNullOrEmpty()) { //module.manifest if (IsModule) { var manifest = ModuleManifest.Clone(); manifest.VersionTag = CustomVersionSuffix; using (var writer = new Utf8StringWriter()) { XmlSerializer xml = new XmlSerializer(typeof(ModuleManifest)); xml.Serialize(writer, manifest); File.WriteAllText(ModuleManifestFile, writer.ToString(), Encoding.UTF8); } } //directory.Build.Props var xmlDoc = new XmlDocument() { PreserveWhitespace = true }; xmlDoc.LoadXml(File.ReadAllText(DirectoryBuildPropsPath)); var suffix = xmlDoc.GetElementsByTagName("VersionSuffix"); suffix[0].InnerText = CustomVersionSuffix; using (var writer = new Utf8StringWriter()) { xmlDoc.Save(writer); File.WriteAllText(DirectoryBuildPropsPath, writer.ToString()); } } base.OnTargetStart(target); }
public void ChangeProjectVersion(string prefix = null, string suffix = null) { //theme if (IsTheme) { //var json = JsonDocument.Parse(File.ReadAllText(PackageJsonPath)); //json.RootElement.GetProperty("version") var json = SerializationTasks.JsonDeserializeFromFile <JObject>(PackageJsonPath); json["version"] = prefix; SerializationTasks.JsonSerializeToFile(json, Path.GetFullPath(PackageJsonPath)); } else { //module.manifest if (IsModule) { var manifest = ModuleManifest.Clone(); if (!String.IsNullOrEmpty(prefix)) { manifest.Version = prefix; } if (!String.IsNullOrEmpty(suffix)) { manifest.VersionTag = suffix; } using (var writer = new Utf8StringWriter()) { XmlSerializer xml = new XmlSerializer(typeof(ModuleManifest)); xml.Serialize(writer, manifest); File.WriteAllText(ModuleManifestFile, writer.ToString(), Encoding.UTF8); } } //Directory.Build.props var xmlDoc = new XmlDocument() { PreserveWhitespace = true }; xmlDoc.LoadXml(File.ReadAllText(DirectoryBuildPropsPath)); if (!String.IsNullOrEmpty(prefix)) { var prefixNodex = xmlDoc.GetElementsByTagName("VersionPrefix"); prefixNodex[0].InnerText = prefix; } if (String.IsNullOrEmpty(VersionSuffix) && !String.IsNullOrEmpty(suffix)) { var suffixNodes = xmlDoc.GetElementsByTagName("VersionSuffix"); suffixNodes[0].InnerText = suffix; } using (var writer = new Utf8StringWriter()) { xmlDoc.Save(writer); File.WriteAllText(DirectoryBuildPropsPath, writer.ToString()); } } }
public void ChangeProjectVersion(string prefix = null, string suffix = null) { //module.manifest if (IsModule) { var manifest = ModuleManifest.Clone(); if (!String.IsNullOrEmpty(prefix)) { manifest.Version = prefix; } if (!String.IsNullOrEmpty(suffix)) { manifest.VersionTag = suffix; } using (var writer = new Utf8StringWriter()) { XmlSerializer xml = new XmlSerializer(typeof(ModuleManifest)); xml.Serialize(writer, manifest); File.WriteAllText(ModuleManifestFile, writer.ToString(), Encoding.UTF8); } } //directory.Build.Props var xmlDoc = new XmlDocument() { PreserveWhitespace = true }; xmlDoc.LoadXml(File.ReadAllText(DirectoryBuildPropsPath)); if (!String.IsNullOrEmpty(prefix)) { var prefixNodex = xmlDoc.GetElementsByTagName("VersionPrefix"); prefixNodex[0].InnerText = prefix; } if (String.IsNullOrEmpty(VersionSuffix) && !String.IsNullOrEmpty(suffix)) { var suffixNodes = xmlDoc.GetElementsByTagName("VersionSuffix"); suffixNodes[0].InnerText = suffix; } using (var writer = new Utf8StringWriter()) { xmlDoc.Save(writer); File.WriteAllText(DirectoryBuildPropsPath, writer.ToString()); } }