Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public override bool Execute()
protected Regex CreateXmlUpdateRegex(string elementName, string contentGroupName) =>
new Regex($@"<{elementName}>(?<{contentGroupName}>.*)</{elementName}>");

protected Regex CreateMSBuildSdkUpdateRegex(string msbuildSdkName, string contentGroupName) =>
new Regex($@"""{msbuildSdkName}""\s*:\s*""(?<{contentGroupName}>.*)""");

protected IEnumerable<IDependencyUpdater> CreateUpdaters()
{
if (ProjectJsonFiles != null && ProjectJsonFiles.Any())
Expand All @@ -98,6 +101,10 @@ protected IEnumerable<IDependencyUpdater> CreateUpdaters()
yield return CreateXmlUpdater(step);
break;

case "MSBuildSdk":
yield return CreateMSBuildSdkUpdater(step);
break;

case "File":
yield return ConfigureFileUpdater(
new FilePackageUpdater
Expand Down Expand Up @@ -256,6 +263,19 @@ private FileRegexUpdater CreateXmlUpdater(ITaskItem step)
return updater;
}

private FileRegexUpdater CreateMSBuildSdkUpdater(ITaskItem step)
{
string packageId = step.GetMetadata("PackageId");

var updater = new FileRegexPackageUpdater
{
PackageId = packageId
};

ConfigureFileRegexUpdater(updater, step);
return updater;
}

private FileUpdater ConfigureFileUpdater(FileUpdater updater, ITaskItem step)
{
updater.SkipIfNoReplacementFound = string.Equals(
Expand Down Expand Up @@ -288,6 +308,7 @@ private FileRegexUpdater ConfigureFileRegexUpdater(FileRegexUpdater updater, ITa

string elementName = step.GetMetadata("ElementName");
string manualRegex = step.GetMetadata("Regex");
string msbuildSdkName = step.GetMetadata("MSBuildSdkName");
if (!string.IsNullOrEmpty(elementName))
{
updater.Regex = CreateXmlUpdateRegex(elementName, nameof(elementName));
Expand All @@ -298,10 +319,15 @@ private FileRegexUpdater ConfigureFileRegexUpdater(FileRegexUpdater updater, ITa
updater.Regex = new Regex(manualRegex);
updater.VersionGroupName = GetRequiredMetadata(step, "VersionGroupName");
}
else if (!string.IsNullOrEmpty(msbuildSdkName))
{
updater.Regex = CreateMSBuildSdkUpdateRegex(Regex.Escape(msbuildSdkName), nameof(msbuildSdkName));

This comment was marked as spam.

This comment was marked as spam.

updater.VersionGroupName = nameof(msbuildSdkName);
}
else
{
throw new ArgumentException(

This comment was marked as spam.

This comment was marked as spam.

$"On '{step.ItemSpec}', did not find 'ElementName' or 'Regex' metadata.");
$"On '{step.ItemSpec}', did not find 'ElementName', 'Regex', or 'MSBuildSdkName' metadata.");
}

updater.SkipIfNoReplacementFound = string.Equals(
Expand Down