I'm struggling to use the contains(text,'some text') from XPATH.
I saw this link How to use XPath contains() but for some reason is not working for me
I need to remove a project reference, so I want to select by only using "ProjectName" (without specifying the full path) I took a script from this answer How do I use Powershell to add/remove references to a csproj? (see RemoveReference.ps1)
Here my code, and also a fiddle https://dotnetfiddle.net/Cq5fa6
using System;
using System.Xml;
public class Program
{
public static void Main()
{
//Declare the XML Document here
XmlDocument Doc = new XmlDocument();
//Load you xml here
//Doc.LoadXml(TransportResponse.Response)
Doc.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project ToolsVersion=""15.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<ItemGroup>
<ProjectReference Include=""..\ProjectReferencesToolkit.Core\ProjectReferencesToolkit.Core.csproj"">
<Project>{6c167ddd-7ce8-4087-9f8c-6986145b97d1}</Project>
<Name>ProjectReferencesToolkit.Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" />
</Project>
");
//I need to use contains here to only search for ProjectReferencesToolkit.Core.csproj (not specifying full path)
var XPath = String.Format("//a:ProjectReference[@Include='{0}']","..\\ProjectReferencesToolkit.Core\\ProjectReferencesToolkit.Core.csproj");
var nsmgr = new XmlNamespaceManager(Doc.NameTable);
nsmgr.AddNamespace("a","http://schemas.microsoft.com/developer/msbuild/2003");
var node = Doc.SelectSingleNode(XPath, nsmgr);
Console.WriteLine(node.InnerXml);
}
}