XmlPoke and Unique Sites

I am trying to use the xmlpoke task to update the VS project file (which is XML). There are several PropertyGroup nodes in the Project root, I'm trying to select the first one. XML looks like this:

<Project> <PropertyGroup> </PropertyGroup> <PropertyGroup> </PropertyGroup> <PropertyGroup> </PropertyGroup> </Project> 

I use xpath from //Project/PropertyGroup[1] to get the first PropertyGroup, but I get the error: "Optional xpath given by // Project / PropertyGroup [1]".

Edit: Sorry, I didn’t think it was important (but it does), Project has a namespace. I put the right XML with the right xmlpoke as the answer for any future search engines.

+5
source share
1 answer

Well, I have simplified the XML fragment above too much - I think that someone would have understood this if I had not done so. The answer is that since Project has a namespace, it should be like

  <xmlpoke file="project_file.csproj" value="v4.0" xpath="//x:Project/x:PropertyGroup[1]/x:TargetFrameworkVersion"> <namespaces> <namespace prefix="x" uri="http://schemas.microsoft.com/developer/msbuild/2003" /> </namespaces> </xmlpoke> 

For reference, the project tag is as follows:

  <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> 
+9
source

Source: https://habr.com/ru/post/911238/


All Articles