我一直在使用Tigris社区任务使用
XMLUpdate任务更新各种AppSettings键.
现在,我想在system.net部分添加一个节点来设置代理.
我宣布了一处房产
<PropertyGroup> <proxy><defaultProxy> <proxy usesystemdefault="False" proxyaddress="http://IPADDRESS:PORT" /> </defaultProxy></proxy> </PropertyGroup>
和XMLUpdate任务看起来像
<XmlUpdate Prefix="n" Namespace="http://schemas.microsoft.com/.NetConfiguration/v2.0" XmlFileName="$(BuildDir)\Builds\_PublishedWebsites\Presentation\Web.config" XPath="/n:configuration/n:system.net" Value="$(proxy)" />
这会更新Web配置,但它会直接从属性组更新,即不转换尖括号的转义字符.有没有人有任何想法?
解决方法
您可以使用XmlMassUpdate而不是XmlUpdate任务.
<ProjectExtensions> <defaultProxy> <proxy usesystemdefault="False" proxyaddress="http://IPADDRESS:PORT"/> </defaultProxy> </ProjectExtensions> <Target Name="SubstituteFromWebConfig"> <XmlMassUpdate NamespaceDeFinitions="msb=http://schemas.microsoft.com/developer/msbuild/2003;n=http://schemas.microsoft.com/.NetConfiguration/v2.0" ContentFile="$(BuildDir)\Builds\_PublishedWebsites\Presentation\Web.config" ContentRoot="/n:configuration/n:system.net" SubstitutionsFile="$(MSBuildProjectFullPath)" SubstitutionsRoot="/msb:Project/msb:ProjectExtensions/msb:system.web" /> </Target>
在此示例中,我们将ContentFile中ContentRoot指向的节点替换为SubstitutionsFile(当前MSBuild文件)中SubstitutionsRoot指向的节点.
此技术利用MSBuild ProjectExtensions元素,该元素允许您将XML添加到MSBuild引擎将忽略的项目文件中.
(或者,如果您不想使用XmlMassUpdate,则可以在ProjectExtensions和XmlUpdate中的节点上使用XmlRead任务.)