gpt4 book ai didi

xml - 如何最好地更新 MSBuild 中的 XML 节点

转载 作者:数据小太阳 更新时间:2023-10-29 01:55:50 24 4
gpt4 key购买 nike

我一直在使用 Tigris 社区任务通过 XMLUpdate 任务更新各种 AppSettings 键。

现在,我想在 system.net 部分添加一个节点来设置代理。

我声明了一个属性

<PropertyGroup>
<proxy>&lt;defaultProxy&gt; &lt;proxy usesystemdefault="False" proxyaddress="http://IPADDRESS:PORT" /&gt; &lt;/defaultProxy&gt;</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>

在此示例中,我们将 ContentFileContentRoot 指向的节点替换为 SubstitutionsFileSubstitutionsRoot 指向的节点>(当前 MSBuild 文件)。

此技术利用了 MSBuild ProjectExtensions 元素,它允许您添加 XML 到项目文件将被 MSBuild 引擎忽略.

(或者如果您不想使用 XmlMassUpdate,您可以在 ProjectExtensions 和 XmlUpdate 中的节点上使用 XmlRead 任务。)

关于xml - 如何最好地更新 MSBuild 中的 XML 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/503730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com