是否可以将 XML 文件(例如配置文件)中的节点标记为“必须转换”并且如果您未在转换文件中指定它,转换将失败?
例如,下面是.config
一个包含必须转换的节点的文件的示例:
<?xml version="1.0"?>
<configuration>
<appSettings>
<!-- Mark this key to be transformed -->
<add key="MyValue" MustBeTransformed="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
</configuration>
因为键值被标记为MustBeTransformed
,所以以下将确保它被正确转换:
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<!-- Without the line below, the transform would fail -->
<add key="MyValue" xdt:Transform="Set a value" />
</appSettings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
我问这个是因为目前我只看到使用.ps1
脚本和 XPath才能做到这一点