WiX – 如何仅在尚不存在的情况下添加XML元素
发布时间:2020-12-16 22:58:56 所属栏目:百科 来源:网络整理
导读:我想在安装期间向 XML添加一个元素,但我想避免升级安装复制我的元素.如何使我的XmlFile组件有条件? 解决方法 你可以使用XmlConfig! 想象一下,我需要创建connectionstring(检查是否存在),如下所示: add name="MyConnection" connectionString="this-is-con
|
我想在安装期间向
XML添加一个元素,但我想避免升级安装复制我的元素.如何使我的XmlFile组件有条件?
解决方法
你可以使用XmlConfig!
想象一下,我需要创建connectionstring(检查是否存在),如下所示: <add name="MyConnection" connectionString="this-is-connection-string" providerName="System.Data.SqlClient" /> 这是我的代码: <?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Fragment>
<Property Id="CONNECTIONSTRING_NAME" Value="MyConnection" />
<SetProperty Id="ThisIsDynamicValue"
Value="/configuration/connectionStrings/add[[]@name='[CONNECTIONSTRING_NAME]'[]]"
After="InstallInitialize" Sequence="execute" />
<DirectoryRef Id="INSTALLFOLDER">
<Component Id="C_ConnectionString" Guid="{35E351D5-1154-4EA0-91AE-F898EEF8C551}">
<!-- First: Make sure that exist a connectionString with name is "MyConnection" -->
<!--Create "add" element-->
<util:XmlConfig Id="CreateConnectionString" Action="create" On="install" Node="element"
File="web.config" VerifyPath="[ThisIsDynamicValue]"
Name="add"
ElementPath="/configuration/connectionStrings"
Sequence="1" />
<!--Create "name" attribute-->
<util:XmlConfig Id="attrName"
File="web.config" ElementId="CreateConnectionString"
Name="name" Value="[CONNECTIONSTRING_NAME]"
Sequence="2" />
<!--Create "connectionString" attribute-->
<util:XmlConfig Id="attrConnString"
File="web.config" ElementId="CreateConnectionString"
Name="connectionString" Value="this-is-connection-string"
Sequence="3" />
<!--Create "providerName" attribute-->
<util:XmlConfig Id="attrProvider"
File="web.config" ElementId="CreateConnectionString"
Name="providerName" Value="System.Data.SqlClient"
Sequence="4" />
<!--Second: Update connectionString-->
<util:XmlFile Id="SpecificScriptConnectionString" Action="setValue" Permanent="yes"
SelectionLanguage="XSLPattern" Sequence="1" Name="connectionString"
File="web.config"
ElementPath="[ThisIsDynamicValue]" Value="this-is-new-value-of-connectionstring-after-updated" />
<CreateFolder />
</Component>
</DirectoryRef>
</Fragment>
</Wix>
祝好运! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
