Datei: Tools/PatchNdoVersion/Program.cs
Last Commit (6f29331)
| 1 | using System.Text; |
| 2 | using System.Text.RegularExpressions; |
| 3 | using System.Xml.Linq; |
| 4 | using System.Linq; |
| 5 | |
| 6 | namespace PatchNdoVersion |
| 7 | { |
| 8 | ····internal class Program |
| 9 | ····{ |
| 10 | ········static int Main(string[] args) |
| 11 | ········{ |
| 12 | ············if (args.Length < 3) |
| 13 | ············{ |
| 14 | ················Console.WriteLine( "usage: PatchNdoVersion <ProjFile> -i <NDOInterfaces-Version> -n <NDO-Version> -e <NDOEnhancer-Version>" ); |
| 15 | ················return -1; |
| 16 | ············} |
| 17 | |
| 18 | ············var projFile = args[0]; |
| 19 | ············string? iVersion = null; |
| 20 | ············string? eVersion = null; |
| 21 | ············string? nVersion = null; |
| 22 | |
| 23 | |
| 24 | ············if (!File.Exists(projFile)) |
| 25 | ············{ |
| 26 | ················Console.WriteLine( $"File doesn't exist: '{projFile}'" ); |
| 27 | ················return -3; |
| 28 | ············} |
| 29 | |
| 30 | |
| 31 | ············try |
| 32 | ············{ |
| 33 | ················Regex regex = new Regex(@"^\d+\.\d+\.\d+"); |
| 34 | ················var changed = false; |
| 35 | ················var i = Array.IndexOf(args, "-i"); |
| 36 | ················if (i > 0) |
| 37 | ················{ |
| 38 | ····················if (args.Length < i + 2) |
| 39 | ························throw new Exception( "Option -i needs a parameter." ); |
| 40 | ···················· |
| 41 | ····················iVersion = args[i + 1]; |
| 42 | |
| 43 | ····················if (!regex.Match( iVersion ).Success) |
| 44 | ························throw new Exception( "Parameter of -i must be a version string" ); |
| 45 | ················} |
| 46 | |
| 47 | ················var e = Array.IndexOf(args, "-e"); |
| 48 | ················if (e > 0) |
| 49 | ················{ |
| 50 | ····················if (args.Length < e + 2) |
| 51 | ························throw new Exception( "Option -e needs a parameter." ); |
| 52 | |
| 53 | ····················eVersion = args[e + 1]; |
| 54 | |
| 55 | ····················if (!regex.Match( eVersion ).Success) |
| 56 | ························throw new Exception( "Parameter of -e must be a version string" ); |
| 57 | ················} |
| 58 | |
| 59 | ················var n = Array.IndexOf(args, "-n"); |
| 60 | ················if (n > 0) |
| 61 | ················{ |
| 62 | ····················if (args.Length < n + 2) |
| 63 | ························throw new Exception( "Option -n needs a parameter." ); |
| 64 | |
| 65 | ····················nVersion = args[n + 1]; |
| 66 | |
| 67 | ····················if (!regex.Match( nVersion ).Success) |
| 68 | ························throw new Exception( "Parameter of -n must be a version string" ); |
| 69 | ················} |
| 70 | ················ |
| 71 | ················string ndoRootPath = AppDomain.CurrentDomain.BaseDirectory; |
| 72 | |
| 73 | ················XDocument doc = XDocument.Load( projFile ); |
| 74 | ················var project = doc.Root!; |
| 75 | |
| 76 | ················var prElement = project.Elements("ItemGroup").FirstOrDefault(pg => pg.Element("PackageReference") != null); ; |
| 77 | ················if (prElement == null) |
| 78 | ····················throw new Exception( "Project file doesn't have PackageReference items" ); |
| 79 | |
| 80 | ················if (iVersion != null) |
| 81 | ················{ |
| 82 | ····················var iElement = prElement.Elements("PackageReference").FirstOrDefault(el => el.Attribute("Include")?.Value == "NDOInterfaces"); |
| 83 | ····················if (iElement != null) |
| 84 | ····················{ |
| 85 | ························if (iElement.Attribute( "Version" )?.Value != iVersion) |
| 86 | ························{ |
| 87 | ····························iElement.Attribute( "Version" )!.Value = iVersion; |
| 88 | ····························changed = true; |
| 89 | ························} |
| 90 | ····················} |
| 91 | ····················else |
| 92 | ····················{ |
| 93 | ························throw new Exception( "Project needs a PackageReference to NDOInterfaces" ); |
| 94 | ····················} |
| 95 | ················} |
| 96 | |
| 97 | ················if (eVersion != null) |
| 98 | ················{ |
| 99 | ····················var eElement = prElement.Elements("PackageReference").FirstOrDefault(el => el.Attribute("Include")?.Value == "NDOEnhancer"); |
| 100 | ····················if (eElement != null) |
| 101 | ····················{ |
| 102 | ························if (eElement.Attribute( "Version" )?.Value != eVersion) |
| 103 | ························{ |
| 104 | ····························eElement.Attribute( "Version" )!.Value = eVersion; |
| 105 | ····························changed = true; |
| 106 | ························} |
| 107 | ····················} |
| 108 | ····················else |
| 109 | ····················{ |
| 110 | ························throw new Exception( "Project needs a PackageReference to NDOEnhancer" ); |
| 111 | ····················} |
| 112 | ················} |
| 113 | |
| 114 | ················if (nVersion != null) |
| 115 | ················{ |
| 116 | ····················var element = prElement.Elements("PackageReference").FirstOrDefault(el => el.Attribute("Include")?.Value.ToLower() == "ndo.dll"); |
| 117 | ····················if (element != null) |
| 118 | ····················{ |
| 119 | ························if (element.Attribute( "Version" )?.Value != nVersion) |
| 120 | ························{ |
| 121 | ····························element.Attribute( "Version" )!.Value = nVersion; |
| 122 | ····························changed = true; |
| 123 | ························} |
| 124 | ····················} |
| 125 | ····················else |
| 126 | ····················{ |
| 127 | ························throw new Exception( "Project needs a PackageReference to NDO.dll" ); |
| 128 | ····················} |
| 129 | ················} |
| 130 | |
| 131 | ················if (changed) |
| 132 | ····················doc.Save(projFile); |
| 133 | |
| 134 | ················return 0; |
| 135 | ············} |
| 136 | ············catch (Exception ex) |
| 137 | ············{ |
| 138 | ················Console.WriteLine( ex.ToString() ); |
| 139 | ················return -1; |
| 140 | ············} |
| 141 | ········} |
| 142 | ····} |
| 143 | } |
| 144 |
New Commit (4666cb7)
| 1 | using System.Text; |
| 2 | using System.Text.RegularExpressions; |
| 3 | using System.Xml.Linq; |
| 4 | using System.Linq; |
| 5 | |
| 6 | namespace PatchNdoVersion |
| 7 | { |
| 8 | ····internal class Program |
| 9 | ····{ |
| 10 | ········static int Main(string[] args) |
| 11 | ········{ |
| 12 | ············if (args.Length < 3) |
| 13 | ············{ |
| 14 | ················Console.WriteLine( "usage: PatchNdoVersion <ProjFile> -i <NDOInterfaces-Version> -n <NDO-Version> -e <NDOEnhancer-Version>" ); |
| 15 | ················return -1; |
| 16 | ············} |
| 17 | |
| 18 | ············var projFile = args[0]; |
| 19 | ············string? iVersion = null; |
| 20 | ············string? eVersion = null; |
| 21 | ············string? nVersion = null; |
| 22 | ············string? mVersion = null; |
| 23 | |
| 24 | |
| 25 | ············if (!File.Exists(projFile)) |
| 26 | ············{ |
| 27 | ················Console.WriteLine( $"File doesn't exist: '{projFile}'" ); |
| 28 | ················return -3; |
| 29 | ············} |
| 30 | |
| 31 | |
| 32 | ············try |
| 33 | ············{ |
| 34 | ················Regex regex = new Regex(@"^\d+\.\d+\.\d+"); |
| 35 | ················var changed = false; |
| 36 | ················var i = Array.IndexOf(args, "-i"); |
| 37 | ················if (i > 0) |
| 38 | ················{ |
| 39 | ····················if (args.Length < i + 2) |
| 40 | ························throw new Exception( "Option -i needs a parameter." ); |
| 41 | ···················· |
| 42 | ····················iVersion = args[i + 1]; |
| 43 | |
| 44 | ····················if (!regex.Match( iVersion ).Success) |
| 45 | ························throw new Exception( "Parameter of -i must be a version string" ); |
| 46 | ················} |
| 47 | |
| 48 | ················var e = Array.IndexOf(args, "-e"); |
| 49 | ················if (e > 0) |
| 50 | ················{ |
| 51 | ····················if (args.Length < e + 2) |
| 52 | ························throw new Exception( "Option -e needs a parameter." ); |
| 53 | |
| 54 | ····················eVersion = args[e + 1]; |
| 55 | |
| 56 | ····················if (!regex.Match( eVersion ).Success) |
| 57 | ························throw new Exception( "Parameter of -e must be a version string" ); |
| 58 | ················} |
| 59 | |
| 60 | ················var n = Array.IndexOf(args, "-n"); |
| 61 | ················if (n > 0) |
| 62 | ················{ |
| 63 | ····················if (args.Length < n + 2) |
| 64 | ························throw new Exception( "Option -n needs a parameter." ); |
| 65 | |
| 66 | ····················nVersion = args[n + 1]; |
| 67 | |
| 68 | ····················if (!regex.Match( nVersion ).Success) |
| 69 | ························throw new Exception( "Parameter of -n must be a version string" ); |
| 70 | ················} |
| 71 | |
| 72 | ················var m = Array.IndexOf(args, "-m"); |
| 73 | ················if (m > 0) |
| 74 | ················{ |
| 75 | ····················if (args.Length < m + 2) |
| 76 | ························throw new Exception( "Option -m needs a parameter." ); |
| 77 | |
| 78 | ····················mVersion = args[m + 1]; |
| 79 | |
| 80 | ····················if (!regex.Match( mVersion ).Success) |
| 81 | ························throw new Exception( "Parameter of -m must be a version string" ); |
| 82 | ················} |
| 83 | |
| 84 | ················string ndoRootPath = AppDomain.CurrentDomain.BaseDirectory; |
| 85 | |
| 86 | ················XDocument doc = XDocument.Load( projFile ); |
| 87 | ················var project = doc.Root!; |
| 88 | |
| 89 | ················var prElement = project.Elements("ItemGroup").FirstOrDefault(pg => pg.Element("PackageReference") != null); ; |
| 90 | ················if (prElement == null) |
| 91 | ····················throw new Exception( "Project file doesn't have PackageReference items" ); |
| 92 | |
| 93 | ················if (iVersion != null) |
| 94 | ················{ |
| 95 | ····················var iElement = prElement.Elements("PackageReference").FirstOrDefault(el => el.Attribute("Include")?.Value == "NDOInterfaces"); |
| 96 | ····················if (iElement != null) |
| 97 | ····················{ |
| 98 | ························if (iElement.Attribute( "Version" )?.Value != iVersion) |
| 99 | ························{ |
| 100 | ····························iElement.Attribute( "Version" )!.Value = iVersion; |
| 101 | ····························changed = true; |
| 102 | ························} |
| 103 | ····················} |
| 104 | ····················else |
| 105 | ····················{ |
| 106 | ························throw new Exception( "Project needs a PackageReference to NDOInterfaces" ); |
| 107 | ····················} |
| 108 | ················} |
| 109 | |
| 110 | ················if (eVersion != null) |
| 111 | ················{ |
| 112 | ····················var eElement = prElement.Elements("PackageReference").FirstOrDefault(el => el.Attribute("Include")?.Value == "NDOEnhancer"); |
| 113 | ····················if (eElement != null) |
| 114 | ····················{ |
| 115 | ························if (eElement.Attribute( "Version" )?.Value != eVersion) |
| 116 | ························{ |
| 117 | ····························eElement.Attribute( "Version" )!.Value = eVersion; |
| 118 | ····························changed = true; |
| 119 | ························} |
| 120 | ····················} |
| 121 | ····················else |
| 122 | ····················{ |
| 123 | ························throw new Exception( "Project needs a PackageReference to NDOEnhancer" ); |
| 124 | ····················} |
| 125 | ················} |
| 126 | |
| 127 | ················if (nVersion != null) |
| 128 | ················{ |
| 129 | ····················var element = prElement.Elements("PackageReference").FirstOrDefault(el => el.Attribute("Include")?.Value.ToLower() == "ndo.dll"); |
| 130 | ····················if (element != null) |
| 131 | ····················{ |
| 132 | ························if (element.Attribute( "Version" )?.Value != nVersion) |
| 133 | ························{ |
| 134 | ····························element.Attribute( "Version" )!.Value = nVersion; |
| 135 | ····························changed = true; |
| 136 | ························} |
| 137 | ····················} |
| 138 | ····················else |
| 139 | ····················{ |
| 140 | ························throw new Exception( "Project needs a PackageReference to NDO.dll" ); |
| 141 | ····················} |
| 142 | ················} |
| 143 | |
| 144 | ················if (mVersion != null) |
| 145 | ················{ |
| 146 | ····················var element = prElement.Elements("PackageReference").FirstOrDefault(el => el.Attribute("Include")?.Value.ToLower() == "ndo.mapping"); |
| 147 | ····················if (element != null) |
| 148 | ····················{ |
| 149 | ························if (element.Attribute( "Version" )?.Value != mVersion) |
| 150 | ························{ |
| 151 | ····························element.Attribute( "Version" )!.Value = mVersion; |
| 152 | ····························changed = true; |
| 153 | ························} |
| 154 | ····················} |
| 155 | ····················else |
| 156 | ····················{ |
| 157 | ························throw new Exception( "Project needs a PackageReference to NDO.mapping" ); |
| 158 | ····················} |
| 159 | ················} |
| 160 | |
| 161 | ················if (changed) |
| 162 | ····················doc.Save(projFile); |
| 163 | |
| 164 | ················return 0; |
| 165 | ············} |
| 166 | ············catch (Exception ex) |
| 167 | ············{ |
| 168 | ················Console.WriteLine( ex.ToString() ); |
| 169 | ················return -1; |
| 170 | ············} |
| 171 | ········} |
| 172 | ····} |
| 173 | } |
| 174 |