How to propertly reference a namespace for Microsoft.Sdc.Tasks.XmlFile.GetValue
- by æther
Hi, i want to use MSBuild to insert a custom xml element into web.config. After looking up online, i found such solution:
1) Store element in the .build file in projectextensions
<ProjectExtensions>
<CustomElement name="CustomElementName">
...
</CustomElement>
</ProjectExtensions>
2) Retrieve the element with GetValue
<Target name="ModifyConfig">
<XmlFile.GetValue Path="$(MSBuildProjectFullPath)"
XPath="Project/ProjectExtensions/CustomElement[@name='CustomElementName']">
<Output TaskParameter="Value" PropertyName="CustomElementProperty"/>
</XmlFile.GetValue>
</Target>
This will not work as i need to reference a namespace the .build project is using for it to find the needed element (checked the .build file with XPath Visualizer). So, i look up for a further solution and come to this:
<ItemGroup>
<XmlNamespace Include="MSBuild">
<Prefix>msb</Prefix>
<Uri>http://schemas.microsoft.com/developer/msbuild/2003</Uri>
</XmlNamespace>
</ItemGroup>
<Target name="ModifyConfig">
<XmlFile.GetValue Path="$(MSBuildProjectFullPath)" Namespaces="$(XmlNamespace)"
XPath="/msb:Project/msb:ProjectExtensions/msb:CustomElement[@name='CustomElementName']"
>
<Output TaskParameter="Value" PropertyName="CustomElementProperty"/>
</XmlFile.GetValue>
</Target>
But for some reason namespace is not recognized - MSBuild reports the following error:
C:...\mybuild.build(53,9): error : A task error has occured.
C:...\mybuild.build(53,9): error : Message = Namespace prefix 'msb' is not
defined.
I tried some variations of referencing it differently but none work, and there is not much about propertly referencing those namespaces online also. Can you tell me what am i doing wrong and how to do it propertly?