Skip to content

Commit

Permalink
Use a generated regex
Browse files Browse the repository at this point in the history
  • Loading branch information
lewing committed Jul 19, 2023
1 parent 015258c commit 7a66289
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Microsoft.Workload.Build.Tasks
{
public class InstallWorkloadFromArtifacts : Task
public partial class InstallWorkloadFromArtifacts : Task
{
[Required, NotNull]
public ITaskItem[] WorkloadIds { get; set; } = Array.Empty<ITaskItem>();
Expand Down Expand Up @@ -49,6 +49,9 @@ public class InstallWorkloadFromArtifacts : Task
private string _tempDir = string.Empty;
private string _nugetCachePath = string.Empty;

[GeneratedRegex(@"^\d+\.\d+\.\d+(-[A-z]*\.*\d*)?")]
private static partial Regex bandVersionRegex();

public override bool Execute()
{
_tempDir = Path.Combine(Path.GetTempPath(), $"workload-{Path.GetRandomFileName()}");
Expand Down Expand Up @@ -294,7 +297,7 @@ private bool InstallWorkloadManifest(ITaskItem workloadId, string name, string v

string outputDir = FindSubDirIgnoringCase(manifestVersionBandDir, name);
// regex matching the version band, e.g. 6.0.100-preview.3.21202.5 => 6.0.100-preview.3
string bandVersion = Regex.Match(version, @"^\d+\.\d+\.\d+(-[A-z]*\.*\d*)?").Value;
string bandVersion = bandVersionRegex().Match(version).Value;

PackageReference pkgRef = new(Name: $"{name}.Manifest-{bandVersion}",
Version: version,
Expand Down

0 comments on commit 7a66289

Please sign in to comment.