|
@@ -0,0 +1,255 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System.Xml;
|
|
|
+
|
|
|
+namespace VersionTool
|
|
|
+{
|
|
|
+ public class AssemblyUpdater
|
|
|
+ {
|
|
|
+ public static void UpdateVersion(string folder, string version)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // var files = Directory.GetFiles(folder, "AssemblyInfo.cs", SearchOption.AllDirectories).Where(x => x.Contains("Properties")).ToArray();
|
|
|
+ // foreach (var file in files)
|
|
|
+ // {
|
|
|
+ // if (File.Exists(file))
|
|
|
+ // {
|
|
|
+ // var sb = new StringBuilder();
|
|
|
+ // string text;
|
|
|
+ // using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read))
|
|
|
+ // {
|
|
|
+ // using (var sr = new StreamReader(fs))
|
|
|
+ // {
|
|
|
+ // string s;
|
|
|
+ // while ((s = sr.ReadLine()) != null)
|
|
|
+ // {
|
|
|
+ // if (s.Contains("assembly: AssemblyVersion"))
|
|
|
+ // {
|
|
|
+ // s = Utility.GetStr(s, version);
|
|
|
+ // }
|
|
|
+ // if (s.Contains("assembly: AssemblyFileVersion"))
|
|
|
+ // {
|
|
|
+ // s = Utility.GetStr(s, version);
|
|
|
+ // }
|
|
|
+ // if (s.Contains("assembly: AssemblyDescription"))
|
|
|
+ // {
|
|
|
+ // s = Utility.GetStr(s, "Powered by VINNO");
|
|
|
+ // }
|
|
|
+ // if (s.Contains("assembly: AssemblyCompany"))
|
|
|
+ // {
|
|
|
+ // s = Utility.GetStr(s, "VINNO Technology (Suzhou) Co. Ltd.");
|
|
|
+ // }
|
|
|
+ // if (s.Contains("assembly: AssemblyProduct"))
|
|
|
+ // {
|
|
|
+ // s = Utility.GetStr(s, "VINNO vCloud System");
|
|
|
+ // }
|
|
|
+ // if (s.Contains("assembly: AssemblyCopyright"))
|
|
|
+ // {
|
|
|
+ // s = Utility.GetStr(s, "Copyright © VINNO 2018");
|
|
|
+ // }
|
|
|
+ // if (s.Contains("assembly: AssemblyTrademark"))
|
|
|
+ // {
|
|
|
+ // s = Utility.GetStr(s, "VINNO");
|
|
|
+ // }
|
|
|
+ // sb.AppendLine(s);
|
|
|
+ // }
|
|
|
+ // text = sb.ToString();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // using (var fs = new FileStream(file, FileMode.Create, FileAccess.Write))
|
|
|
+ // {
|
|
|
+ // using (var sw = new StreamWriter(fs, Encoding.UTF8))
|
|
|
+ // {
|
|
|
+ // sw.Write(text);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // files = Directory.GetFiles(folder, "Info.plist", SearchOption.AllDirectories);
|
|
|
+ // foreach (var file in files)
|
|
|
+ // {
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // if (File.Exists(file))
|
|
|
+ // {
|
|
|
+ // //XML
|
|
|
+ // var document = new XmlDocument();
|
|
|
+ // document.Load(file);
|
|
|
+ // var root = document.SelectSingleNode("plist");
|
|
|
+ // if (root != null)
|
|
|
+ // {
|
|
|
+ // var dict = root.SelectSingleNode("dict");
|
|
|
+ // SetVersion(version, dict, "CFBundleVersion");
|
|
|
+ // SetVersion(version, dict, "CFBundleShortVersionString");
|
|
|
+ // }
|
|
|
+ // document.Save(file);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // catch (Exception e)
|
|
|
+ // {
|
|
|
+ // Console.WriteLine($"load XML[{file}] err:{e}");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // files = Directory.GetFiles(folder, "*.Core.csproj", SearchOption.AllDirectories);
|
|
|
+ // UpdateFileVersion(version, files);
|
|
|
+ // files = Directory.GetFiles(folder, "*.Management.csproj", SearchOption.AllDirectories);
|
|
|
+ // UpdateFileVersion(version, files);
|
|
|
+ var files = Directory.GetFiles(folder, "*.csproj", SearchOption.AllDirectories);
|
|
|
+ // UpdateStandardProjectVersion(version, files);
|
|
|
+ UpdateNetProjectVersion(version, files);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Console.WriteLine(e.Message + e.StackTrace);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// .net 6.0 工程 更新版本
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="version"></param>
|
|
|
+ /// <param name="files"></param>
|
|
|
+ private static void UpdateNetProjectVersion(string version, string[] files)
|
|
|
+ {
|
|
|
+ foreach (var file in files)
|
|
|
+ {
|
|
|
+ if (File.Exists(file))
|
|
|
+ {
|
|
|
+ //XML
|
|
|
+ var document = new XmlDocument();
|
|
|
+ document.Load(file);
|
|
|
+ var root = document.SelectSingleNode("Project");
|
|
|
+ if (root != null)
|
|
|
+ {
|
|
|
+ var propertyGroupNode = root.SelectSingleNode("PropertyGroup");
|
|
|
+ if (propertyGroupNode != null)
|
|
|
+ {
|
|
|
+ var versionNode = propertyGroupNode.SelectSingleNode("Version");
|
|
|
+ if (versionNode == null)
|
|
|
+ {
|
|
|
+ versionNode = document.CreateElement("Version");
|
|
|
+ propertyGroupNode.AppendChild(versionNode);
|
|
|
+ }
|
|
|
+
|
|
|
+ versionNode.InnerText = version;
|
|
|
+
|
|
|
+ var assemblyVersionNode = propertyGroupNode.SelectSingleNode("AssemblyVersion");
|
|
|
+ if (assemblyVersionNode == null)
|
|
|
+ {
|
|
|
+ assemblyVersionNode = document.CreateElement("AssemblyVersion");
|
|
|
+ propertyGroupNode.AppendChild(assemblyVersionNode);
|
|
|
+ }
|
|
|
+ assemblyVersionNode.InnerText = version;
|
|
|
+ var fileVersionNode = propertyGroupNode.SelectSingleNode("FileVersion");
|
|
|
+ if (fileVersionNode == null)
|
|
|
+ {
|
|
|
+ fileVersionNode = document.CreateElement("FileVersion");
|
|
|
+ propertyGroupNode.AppendChild(fileVersionNode);
|
|
|
+ }
|
|
|
+ fileVersionNode.InnerText = version;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ document.Save(file);
|
|
|
+ Console.WriteLine("VersionTool updated versions File: " + file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // private static void UpdateFileVersion(string version, string[] files)
|
|
|
+ // {
|
|
|
+ // foreach (var file in files)
|
|
|
+ // {
|
|
|
+ // if (File.Exists(file))
|
|
|
+ // {
|
|
|
+ // //XML
|
|
|
+ // var document = new XmlDocument();
|
|
|
+ // document.Load(file);
|
|
|
+ // var root = document.SelectSingleNode("Project");
|
|
|
+ // if (root != null)
|
|
|
+ // {
|
|
|
+ // var propertyGroups = root.SelectNodes("PropertyGroup");
|
|
|
+ // if (propertyGroups != null && propertyGroups.Count > 0)
|
|
|
+ // {
|
|
|
+ // foreach (XmlNode node in propertyGroups)
|
|
|
+ // {
|
|
|
+ // var assemblyVersionNode = node.SelectSingleNode("AssemblyVersion");
|
|
|
+ // if (assemblyVersionNode != null)
|
|
|
+ // {
|
|
|
+ // assemblyVersionNode.InnerText = version;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // var versionNode = node.SelectSingleNode("Version");
|
|
|
+ // if (versionNode != null)
|
|
|
+ // {
|
|
|
+ // versionNode.InnerText = version;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // document.Save(file);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // private static void UpdateStandardProjectVersion(string version, string[] files)
|
|
|
+ // {
|
|
|
+ // foreach (var file in files)
|
|
|
+ // {
|
|
|
+ // if (File.Exists(file))
|
|
|
+ // {
|
|
|
+ // //XML
|
|
|
+ // var document = new XmlDocument();
|
|
|
+ // document.Load(file);
|
|
|
+ // var root = document.SelectSingleNode("Project");
|
|
|
+ // if (root != null)
|
|
|
+ // {
|
|
|
+ // var propertyGroupNode = root.SelectSingleNode("PropertyGroup");
|
|
|
+ // if (propertyGroupNode != null)
|
|
|
+ // {
|
|
|
+ // var targetFrameworkNode = propertyGroupNode.SelectSingleNode("TargetFramework");
|
|
|
+ // if (targetFrameworkNode != null && targetFrameworkNode.InnerText.StartsWith("netstandard"))
|
|
|
+ // {
|
|
|
+ // var versionNode = propertyGroupNode.SelectSingleNode("Version");
|
|
|
+ // if (versionNode == null)
|
|
|
+ // {
|
|
|
+ // versionNode = document.CreateElement("Version");
|
|
|
+ // propertyGroupNode.AppendChild(versionNode);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // versionNode.InnerText = version;
|
|
|
+
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // document.Save(file);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // private static void SetVersion(string version, XmlNode dict, string fieldNeedToSetVersion)
|
|
|
+ // {
|
|
|
+ // var index = 0;
|
|
|
+ // if (dict != null)
|
|
|
+ // {
|
|
|
+ // foreach (XmlNode item in dict.ChildNodes)
|
|
|
+ // {
|
|
|
+ // index++;
|
|
|
+ // if (item.InnerText == fieldNeedToSetVersion)
|
|
|
+ // {
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // var v = Version.Parse(version);
|
|
|
+ // dict.ChildNodes[index].InnerText = $"{v.Major}.{v.Minor}.{v.Build}";
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|