解决方法
你可以使用XmlConfig!
想象一下,我需要创建connectionstring(检查是否存在),如下所示:
想象一下,我需要创建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>
祝好运!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。