@@ -207,7 +207,7 @@ internal static string GetPath( BuildContext context, BuildConfiguration configu
207207 var product = context . Product ;
208208
209209 var privateArtifactsRelativeDir =
210- product . PrivateArtifactsDirectory . ToString ( new BuildInfo ( null , configuration , product , null ) ) ;
210+ product . PrivateArtifactsDirectory . ToString ( new BuildArguments ( null , configuration , product , null ) ) ;
211211
212212 var artifactsDir = Path . Combine ( context . RepoDirectory , privateArtifactsRelativeDir ) ;
213213
@@ -222,10 +222,18 @@ internal static string GetPath( BuildContext context, BuildConfiguration configu
222222 /// </summary>
223223 public static bool TryRead (
224224 BuildContext context ,
225- MainVersionFile mainVersionFile ,
225+ BuildConfiguration configuration ,
226226 [ NotNullWhen ( true ) ] out ArtifactManifestVersionInfo ? artifactManifestVersionInfo )
227227 {
228228 var product = context . Product ;
229+
230+ if ( ! MainVersionFile . TryRead ( context , out var mainVersionFile ) )
231+ {
232+ artifactManifestVersionInfo = null ;
233+
234+ return false ;
235+ }
236+
229237 var overriddenPatchVersion = mainVersionFile . OverriddenPatchVersion ;
230238
231239 string ? mainVersion ;
@@ -251,15 +259,12 @@ public static bool TryRead(
251259 {
252260 // If no OverridenPatchVersion is defined, we use MainVersion property from private artifact.
253261
254- var artifactVersionFile = Path . Combine (
255- context . RepoDirectory ,
256- context . Product . PrivateArtifactsDirectory . ToString ( ) ,
257- context . Product . ProductName + ".version.props" ) ;
262+ var artifactVersionFile = context . GetManifestFilePath ( configuration ) ;
258263
259264 var document = XDocument . Load ( artifactVersionFile ) ;
260265 var project = document . Root ;
261266 var properties = project ? . Element ( "PropertyGroup" ) ;
262- var propertyName = $ "{ context . Product . ProductNameWithoutDot } MainVersion";
267+ var propertyName = $ "{ product . ProductNameWithoutDot } MainVersion";
263268 mainVersion = properties ? . Element ( propertyName ) ? . Value ;
264269
265270 if ( mainVersion == null )
@@ -281,4 +286,67 @@ public static bool TryRead(
281286
282287 return true ;
283288 }
289+
290+ public static BuildArguments CreateParametricStringArguments ( BuildContext context , BuildConfiguration buildConfiguration )
291+ {
292+ var product = context . Product ;
293+ var versionFilePath = context . GetManifestFilePath ( buildConfiguration ) ;
294+
295+ if ( ! File . Exists ( versionFilePath ) )
296+ {
297+ throw new FileNotFoundException ( $ "The file '{ versionFilePath } ' should exist before calling this method." ) ;
298+ }
299+
300+ var versionFile = Project . FromFile ( versionFilePath , MSBuildLoadOptions . IgnoreImportErrors ) ;
301+
302+ string packageVersion ;
303+
304+ if ( product . GenerateArcadeProperties )
305+ {
306+ packageVersion = versionFile . Properties
307+ . Single ( p => p . Name == product . ProductNameWithoutDot + "VersionPrefix" )
308+ . EvaluatedValue ;
309+
310+ var suffix = versionFile
311+ . Properties
312+ . Single ( p => p . Name == product . ProductNameWithoutDot + "VersionSuffix" )
313+ . EvaluatedValue ;
314+
315+ if ( ! string . IsNullOrWhiteSpace ( suffix ) )
316+ {
317+ packageVersion = packageVersion + "-" + suffix ;
318+ }
319+ }
320+ else
321+ {
322+ packageVersion = versionFile
323+ . Properties
324+ . Single ( p => p . Name == product . ProductNameWithoutDot + "Version" )
325+ . EvaluatedValue ;
326+ }
327+
328+ if ( string . IsNullOrEmpty ( packageVersion ) )
329+ {
330+ throw new InvalidOperationException ( "PackageVersion should not be null." ) ;
331+ }
332+
333+ var configuration = versionFile
334+ . Properties
335+ . Single ( p => p . Name == product . ProductNameWithoutDot + "BuildConfiguration" )
336+ . EvaluatedValue ;
337+
338+ var packagePreviewVersion = versionFile
339+ . Properties
340+ . Single ( p => p . Name == product . ProductNameWithoutDot + "PreviewVersion" )
341+ . EvaluatedValue ;
342+
343+ if ( string . IsNullOrEmpty ( configuration ) )
344+ {
345+ throw new InvalidOperationException ( "BuildConfiguration should not be null." ) ;
346+ }
347+
348+ ProjectCollection . GlobalProjectCollection . UnloadAllProjects ( ) ;
349+
350+ return new BuildArguments ( packageVersion , Enum . Parse < BuildConfiguration > ( configuration ) , product , packagePreviewVersion ) ;
351+ }
284352}
0 commit comments