How to delete a node in csproj file in c#?
See the question and my original answer on StackOverflowWhen you a SelectNodes or SingleSelectNodes returns nothing, it means your query is wrong. In this case, elements in a .csproj belong to a namespace (here declared as the "default" namespace - w/o a prefix)
<Project ... xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
</Project>
So your code must be changed into this:
XmlDocument doc = new XmlDocument();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("p", "http://schemas.microsoft.com/developer/msbuild/2003");
doc.Load(fullFilePath);
XmlNode node = doc.SelectSingleNode(@"/p:Project/p:ItemGroup/p:Reference[@Include='System.Data']", nsmgr);
node.ParentNode.RemoveChild(node);
doc.Save(fullFilePath);
Note the prefix "p" can be anything, it just allows you to specify a corresponding namespace in the XPATH expression, but you need it, even if in the original document it's declared as the default namespace.