File tree Expand file tree Collapse file tree 1 file changed +28
-9
lines changed
Expand file tree Collapse file tree 1 file changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -15,19 +15,15 @@ public static string GetAppVersion(string defaultVersion = "1.0.0")
1515 {
1616 try
1717 {
18- if ( File . Exists ( Environment . ProcessPath ) )
18+ var filePath = Assembly . GetEntryAssembly ( ) ? . Location ;
19+ if ( TryGetFileVersion ( filePath , out var asmVersion ) )
1920 {
20- var versionInfo = FileVersionInfo . GetVersionInfo ( Environment . ProcessPath ) ;
21- if ( ! string . IsNullOrEmpty ( versionInfo . FileVersion ) )
22- {
23- return versionInfo . FileVersion ;
24- }
21+ return asmVersion ;
2522 }
2623
27- var asmVersion = Assembly . GetEntryAssembly ( ) ? . GetName ( ) . Version ;
28- if ( asmVersion is not null && asmVersion > new Version ( 1 , 0 , 0 ) )
24+ if ( TryGetFileVersion ( Environment . ProcessPath , out var exeVersion ) )
2925 {
30- return asmVersion . ToString ( ) ;
26+ return exeVersion ;
3127 }
3228
3329 return defaultVersion ;
@@ -37,5 +33,28 @@ public static string GetAppVersion(string defaultVersion = "1.0.0")
3733 return defaultVersion ;
3834 }
3935 }
36+
37+ private static bool TryGetFileVersion ( string filePath , out string version )
38+ {
39+ try
40+ {
41+ if ( File . Exists ( filePath ) )
42+ {
43+ var versionInfo = FileVersionInfo . GetVersionInfo ( filePath ) ;
44+ if ( Version . TryParse ( versionInfo . FileVersion , out _ ) )
45+ {
46+ version = versionInfo . FileVersion ;
47+ return true ;
48+ }
49+ }
50+ }
51+ catch
52+ {
53+ // Ignored.
54+ }
55+
56+ version = string . Empty ;
57+ return false ;
58+ }
4059 }
4160}
You can’t perform that action at this time.
0 commit comments