Skip to content

Commit 749c065

Browse files
committed
When adding missing elements to csproj file, only add the new propertyGroup element if there is anything to add to the csproj file
1 parent 857146a commit 749c065

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/CodeUpdater/CodeUpdater/Updaters/CsProjUpdater.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ private void UpdateOrAddCsProjValues(XDocument csProjXmlDoc, List<XElement> prop
105105

106106
private void AddMissingElements(XDocument csProjXmlDoc, CsprojUpdateGroupTracker updateGroup)
107107
{
108+
var toUpdate = updateGroup.UpdateTrackers.Where(x => !x.HasMadeRequiredUpdate()).ToImmutableArray();
109+
110+
if (!toUpdate.Any())
111+
{
112+
return;
113+
}
114+
108115
XElement? propertyGroupToAddTo = null;
109116
if (updateGroup.NotFoundAction == CsprojUpdateGroupTracker.NotFoundActionType.AddElementToFirstPropertyGroup)
110117
{
@@ -113,16 +120,12 @@ private void AddMissingElements(XDocument csProjXmlDoc, CsprojUpdateGroupTracker
113120
else if (updateGroup.NotFoundAction == CsprojUpdateGroupTracker.NotFoundActionType.AddElementToNewPropertyGroup)
114121
{
115122
Logger.Information("Adding new PropertyGroup element for other required elements");
116-
var newPropertyGroup = new XElement("PropertyGroup");
117-
csProjXmlDoc.Root!.Add(newPropertyGroup);
118-
119-
propertyGroupToAddTo = newPropertyGroup;
123+
propertyGroupToAddTo = new XElement("PropertyGroup");
124+
csProjXmlDoc.Root!.Add(propertyGroupToAddTo);
120125
}
121126

122127
//Add the trackers that haven't already set the final value
123-
var toUpdate = updateGroup.UpdateTrackers.Where(x => !x.HasMadeRequiredUpdate()).ToImmutableArray();
124-
if (propertyGroupToAddTo is not null
125-
&& toUpdate.Any())
128+
if (propertyGroupToAddTo is not null)
126129
{
127130
foreach (var trackers in toUpdate)
128131
{

0 commit comments

Comments
 (0)