@@ -78,22 +78,47 @@ public async Task ValidateAsync(string path, CancellationToken ct = default)
78
78
79
79
public class AssemblyVersionDownloadValidator : IDownloadValidator
80
80
{
81
- private readonly string _expectedAssemblyVersion ;
81
+ private readonly int _expectedMajor ;
82
+ private readonly int _expectedMinor ;
83
+ private readonly int _expectedBuild ;
84
+ private readonly int _expectedRevision ;
85
+
86
+ private readonly Version _expectedVersion ;
82
87
83
88
// ReSharper disable once ConvertToPrimaryConstructor
84
- public AssemblyVersionDownloadValidator ( string expectedAssemblyVersion )
89
+ public AssemblyVersionDownloadValidator ( int expectedMajor , int expectedMinor , int expectedBuild ,
90
+ int expectedRevision )
85
91
{
86
- _expectedAssemblyVersion = expectedAssemblyVersion ;
92
+ _expectedMajor = expectedMajor ;
93
+ _expectedMinor = expectedMinor ;
94
+ _expectedBuild = expectedBuild < 0 ? - 1 : expectedBuild ;
95
+ _expectedRevision = expectedRevision < 0 ? - 1 : expectedRevision ;
96
+ if ( _expectedBuild == - 1 && _expectedRevision != - 1 )
97
+ throw new ArgumentException ( "Build must be set if Revision is set" , nameof ( expectedRevision ) ) ;
98
+
99
+ if ( _expectedBuild == - 1 )
100
+ _expectedVersion = new Version ( _expectedMajor , _expectedMinor ) ;
101
+ else if ( _expectedRevision == - 1 )
102
+ _expectedVersion = new Version ( _expectedMajor , _expectedMinor , _expectedBuild ) ;
103
+ else
104
+ _expectedVersion = new Version ( _expectedMajor , _expectedMinor , _expectedBuild , _expectedRevision ) ;
87
105
}
88
106
89
107
public Task ValidateAsync ( string path , CancellationToken ct = default )
90
108
{
91
109
var info = FileVersionInfo . GetVersionInfo ( path ) ;
92
110
if ( string . IsNullOrEmpty ( info . ProductVersion ) )
93
111
throw new Exception ( "File ProductVersion is empty or null, was the binary compiled correctly?" ) ;
94
- if ( info . ProductVersion != _expectedAssemblyVersion )
112
+ if ( ! Version . TryParse ( info . ProductVersion , out var productVersion ) )
113
+ throw new Exception ( $ "File ProductVersion '{ info . ProductVersion } ' is not a valid version string") ;
114
+
115
+ // If the build or revision are -1 on the expected version, they are ignored.
116
+ if ( productVersion . Major != _expectedMajor || productVersion . Minor != _expectedMinor ||
117
+ ( _expectedBuild != - 1 && productVersion . Build != _expectedBuild ) ||
118
+ ( _expectedRevision != - 1 && productVersion . Revision != _expectedRevision ) )
95
119
throw new Exception (
96
- $ "File ProductVersion is '{ info . ProductVersion } ', but expected '{ _expectedAssemblyVersion } '") ;
120
+ $ "File ProductVersion is '{ info . ProductVersion } ', but expected '{ _expectedVersion } '") ;
121
+
97
122
return Task . CompletedTask ;
98
123
}
99
124
}
@@ -103,19 +128,24 @@ public Task ValidateAsync(string path, CancellationToken ct = default)
103
128
/// </summary>
104
129
public class CombinationDownloadValidator : IDownloadValidator
105
130
{
106
- private readonly IDownloadValidator [ ] _validators ;
131
+ private readonly List < IDownloadValidator > _validators ;
107
132
108
133
/// <param name="validators">Validators to run</param>
109
134
public CombinationDownloadValidator ( params IDownloadValidator [ ] validators )
110
135
{
111
- _validators = validators ;
136
+ _validators = validators . ToList ( ) ;
112
137
}
113
138
114
139
public async Task ValidateAsync ( string path , CancellationToken ct = default )
115
140
{
116
141
foreach ( var validator in _validators )
117
142
await validator . ValidateAsync ( path , ct ) ;
118
143
}
144
+
145
+ public void Add ( IDownloadValidator validator )
146
+ {
147
+ _validators . Add ( validator ) ;
148
+ }
119
149
}
120
150
121
151
/// <summary>
0 commit comments