Skip to content

Commit b07fa17

Browse files
committed
Do not add repeated files to project
1 parent 3dbec8e commit b07fa17

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

ProtoBuf.Project/MSBuildProject.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ public void AddItem(string protoFile)
8282
xe3.InnerText = "MSBuild:Compile";
8383
xe2.AppendChild(xe3);
8484

85-
var protoBufNode = xd.SelectSingleNode("/msbuild:Project/msbuild:ItemGroup/msbuild:ProtoBuf", xnm);
86-
if (protoBufNode == null)
85+
var protoBufNodes = xd.SelectNodes("/msbuild:Project/msbuild:ItemGroup/msbuild:ProtoBuf", xnm);
86+
if (protoBufNodes.Count == 0)
8787
{
88-
protoBufNode = xd.CreateElement("ItemGroup", msbuildNS);
88+
var protoBufNode = xd.CreateElement("ItemGroup", msbuildNS);
8989
var itemGroupNodes = xd.SelectNodes("/msbuild:Project/msbuild:ItemGroup", xnm);
9090
if (itemGroupNodes.Count > 0)
9191
xd.DocumentElement.InsertAfter(protoBufNode, itemGroupNodes[itemGroupNodes.Count - 1]);
@@ -94,7 +94,10 @@ public void AddItem(string protoFile)
9494
protoBufNode.AppendChild(xe2);
9595
}
9696
else
97-
protoBufNode.ParentNode.AppendChild(xe2);
97+
{
98+
if (!protoBufNodes.Cast<XmlElement>().Any(a => a.GetAttribute("Include") == protoFile))
99+
protoBufNodes[protoBufNodes.Count - 1].ParentNode.AppendChild(xe2);
100+
}
98101
}
99102

100103
public void Save(string projectFile)

0 commit comments

Comments
 (0)