1
+ // -----------------------------------------------------------------------
2
+ // <copyright file="ReadmeBuInstallerVersionUpdater.cs">
3
+ // Copyright (c) 2021 Dean Edis. All rights reserved.
4
+ // </copyright>
5
+ // <summary>
6
+ // This example is provided on an "as is" basis and without warranty of any kind.
7
+ // We do not warrant or make any representations regarding the use or
8
+ // results of use of this example.
9
+ // </summary>
10
+ // -----------------------------------------------------------------------
11
+
12
+ using System . IO ;
13
+ using System . Linq ;
14
+ using System . Reflection ;
15
+ using NUnit . Framework ;
16
+
17
+ namespace UnitTests
18
+ {
19
+ [ TestFixture ]
20
+ public class ReadmeBuInstallerVersionUpdater
21
+ {
22
+ [ Test ]
23
+ public void UpdateInstallerVersion ( )
24
+ {
25
+ var rootDir = new FileInfo ( Assembly . GetExecutingAssembly ( ) . Location ) . Directory ;
26
+ while ( ! rootDir . EnumerateFiles ( "*.md" ) . Any ( ) )
27
+ rootDir = rootDir . Parent ;
28
+
29
+ // Get app version.
30
+ var assemblyInfoFile = rootDir . EnumerateFiles ( "ShaderShrinker/Shrinker.WpfApp/Properties/AssemblyInfo.cs" ) . First ( ) ;
31
+ var assemblyVersionLine = File . ReadAllLines ( assemblyInfoFile . FullName ) . First ( o => o . StartsWith ( "[assembly: AssemblyVersion(" ) ) ;
32
+ var assemblyVersion = assemblyVersionLine . Substring ( 28 ) . Replace ( ".0.0\" )]" , null ) ;
33
+
34
+ // Open installer .iss.
35
+ var issFile = rootDir . EnumerateFiles ( "InstallScript.iss" , SearchOption . AllDirectories ) . FirstOrDefault ( ) ;
36
+ Assert . That ( issFile , Is . Not . Null ) ;
37
+ var issLines = File . ReadAllLines ( issFile . FullName ) ;
38
+
39
+ for ( var i = 0 ; i < issLines . Length ; i ++ )
40
+ {
41
+ if ( issLines [ i ] . StartsWith ( "AppVersion=" ) )
42
+ issLines [ i ] = $ "AppVersion={ assemblyVersion } ";
43
+ }
44
+
45
+ File . WriteAllLines ( issFile . FullName , issLines ) ;
46
+ }
47
+ }
48
+ }
0 commit comments