Datei: Tools/PatchNdoVersion/Program.cs
Last Commit (37eab6b)
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 i = Array.IndexOf(args, "-i"); |
35 | ················if (i > 0) |
36 | ················{ |
37 | ····················if (args.Length < i + 2) |
38 | ························throw new Exception( "Option -i needs a parameter." ); |
39 | ···················· |
40 | ····················iVersion = args[i + 1]; |
41 | |
42 | ····················if (!regex.Match( iVersion ).Success) |
43 | ························throw new Exception( "Parameter of -i must be a version string" ); |
44 | ················} |
45 | |
46 | ················var e = Array.IndexOf(args, "-e"); |
47 | ················if (e > 0) |
48 | ················{ |
49 | ····················if (args.Length < e + 2) |
50 | ························throw new Exception( "Option -e needs a parameter." ); |
51 | |
52 | ····················eVersion = args[e + 1]; |
53 | |
54 | ····················if (!regex.Match( eVersion ).Success) |
55 | ························throw new Exception( "Parameter of -e must be a version string" ); |
56 | ················} |
57 | |
58 | ················var n = Array.IndexOf(args, "-n"); |
59 | ················if (n > 0) |
60 | ················{ |
61 | ····················if (args.Length < n + 2) |
62 | ························throw new Exception( "Option -n needs a parameter." ); |
63 | |
64 | ····················nVersion = args[n + 1]; |
65 | |
66 | ····················if (!regex.Match( nVersion ).Success) |
67 | ························throw new Exception( "Parameter of -n must be a version string" ); |
68 | ················} |
69 | ················ |
70 | ················string ndoRootPath = AppDomain.CurrentDomain.BaseDirectory; |
71 | |
72 | ················XDocument doc = XDocument.Load( projFile ); |
73 | ················var project = doc.Root!; |
74 | |
75 | ················var prElement = project.Elements("ItemGroup").FirstOrDefault(pg => pg.Element("PackageReference") != null); ; |
76 | ················if (prElement == null) |
77 | ····················throw new Exception( "Project file doesn't have PackageReference items" ); |
78 | |
79 | ················if (iVersion != null) |
80 | ················{ |
81 | ····················var iElement = prElement.Elements("PackageReference").FirstOrDefault(el => el.Attribute("Include")?.Value == "NDOInterfaces"); |
82 | if ( iElement != null) |
83 | ····················{ |
84 | ························iElement.Attribute( "Version" )!.Value = iVersion; |
85 | ····················} |
86 | ····················else |
87 | ····················{ |
88 | ························throw new Exception( "Project needs a PackageReference to NDOInterfaces" ); |
89 | ····················} |
90 | ················} |
91 | |
92 | ················if (eVersion != null) |
93 | ················{ |
94 | ····················var eElement = prElement.Elements("PackageReference").FirstOrDefault(el => el.Attribute("Include")?.Value == "NDOEnhancer"); |
95 | if ( eElement != null) |
96 | ····················{ |
97 | ························eElement.Attribute( "Version" )!.Value = eVersion; |
98 | ····················} |
99 | ····················else |
100 | ····················{ |
101 | ························throw new Exception( "Project needs a PackageReference to NDOEnhancer" ); |
102 | ····················} |
103 | ················} |
104 | |
105 | ················if (nVersion != null) |
106 | ················{ |
107 | ····················var element = prElement.Elements("PackageReference").FirstOrDefault(el => el.Attribute("Include")?.Value.ToLower() == "ndo.dll"); |
108 | if ( element != null) |
109 | ····················{ |
110 | ························element.Attribute( "Version" )!.Value = nVersion; |
111 | ····················} |
112 | ····················else |
113 | ····················{ |
114 | ························throw new Exception( "Project needs a PackageReference to NDO.dll" ); |
115 | ····················} |
116 | ················} |
117 | |
118 | ················doc.Save(projFile); |
119 | |
120 | ················return 0; |
121 | ············} |
122 | ············catch (Exception ex) |
123 | ············{ |
124 | ················Console.WriteLine( ex.ToString() ); |
125 | ················return -1; |
126 | ············} |
127 | ········} |
128 | ····} |
129 | } |
130 |
New Commit (950e3ef)
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 && iElement. Attribute( "Version") ?. Value != iVersion) |
84 | ····················{ |
85 | ························iElement.Attribute( "Version" )!.Value = iVersion; |
86 | ························changed = true; |
87 | ····················} |
88 | ····················else |
89 | ····················{ |
90 | ························throw new Exception( "Project needs a PackageReference to NDOInterfaces" ); |
91 | ····················} |
92 | ················} |
93 | |
94 | ················if (eVersion != null) |
95 | ················{ |
96 | ····················var eElement = prElement.Elements("PackageReference").FirstOrDefault(el => el.Attribute("Include")?.Value == "NDOEnhancer"); |
97 | if ( eElement != null && eElement. Attribute( "Version" ) ?. Value != eVersion) |
98 | ····················{ |
99 | ························eElement.Attribute( "Version" )!.Value = eVersion; |
100 | ························changed = true; |
101 | ····················} |
102 | ····················else |
103 | ····················{ |
104 | ························throw new Exception( "Project needs a PackageReference to NDOEnhancer" ); |
105 | ····················} |
106 | ················} |
107 | |
108 | ················if (nVersion != null) |
109 | ················{ |
110 | ····················var element = prElement.Elements("PackageReference").FirstOrDefault(el => el.Attribute("Include")?.Value.ToLower() == "ndo.dll"); |
111 | if ( element != null && element. Attribute( "Version" ) ?. Value != nVersion) |
112 | ····················{ |
113 | ························element.Attribute( "Version" )!.Value = nVersion; |
114 | ························changed = true; |
115 | ····················} |
116 | ····················else |
117 | ····················{ |
118 | ························throw new Exception( "Project needs a PackageReference to NDO.dll" ); |
119 | ····················} |
120 | ················} |
121 | |
122 | ················if (changed) |
123 | ····················doc.Save(projFile); |
124 | |
125 | ················return 0; |
126 | ············} |
127 | ············catch (Exception ex) |
128 | ············{ |
129 | ················Console.WriteLine( ex.ToString() ); |
130 | ················return -1; |
131 | ············} |
132 | ········} |
133 | ····} |
134 | } |
135 |