Wix Installer - 更新多个连接字符串

时间:2014-09-09 12:54:02

标签: c# wix installer windows-installer connection-string

我对Wix有一些经验。最初我有一个带有一个连接字符串的配置文件(下面的第一个),安装程序工作正常。现在我添加了另一个连接字符串,我遇到了问题。 XML:

<util:XmlFile Id="leID2" File="[INSTALLFOLDER]Queue.exe.config" Sequence="3" Action="setValue" ElementPath="/configuration/connectionStrings/add[@name='String1']/@connectionString" Value="metadata=res://*/EntityModels.String1.csdl|res://*/EntityModels.String1.ssdl|res://*/EntityModels.String1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=[DBSERVER];initial catalog=[DBNAME];User=User;Password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" Permanent="yes" />

<util:XmlFile Id="leID3" File="[INSTALLFOLDER]Queue.exe.config" Sequence="4" Action="setValue" ElementPath="/configuration/connectionStrings/add[@name='String2']/@connectionString" Value="metadata=res://*/EntityModels.String2.csdl|res://*/EntityModels.String2.ssdl|res://*/EntityModels.String2.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=[DBSERVER];initial catalog=[SECONDDBNAME];User=User;Password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" Permanent="yes" />

DBSERVER,DBNAME,SECONDDBNAME是从自定义用户输入窗口设置的所有属性。当我安装时,这是配置文件中的结果:

<add name="String1" connectionString="metadata=res://*/EntityModels.String1.csdl|res://*/EntityModels.String1.ssdl|res://*/EntityModels.String1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=**mydbserver**;initial catalog=**seconddbname**;User=User;Password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient"/>

 <add name="String2" connectionString="metadata=res://*/EntityModels.String2.csdl|res://*/EntityModels.String2.ssdl|res://*/EntityModels.String2.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=[default from project];initial catalog=[default from project];User=User;Password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient"/>

因此第一个连接字符串正确获取DBSERVER名称,但它输入了第二个DB名称。 第二个连接字符串与我在visual studio项目中保持完全不变。它没有被修改。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

由于您使用的是XPATH,因此需要在util:XmlFile节点中设置此属性:

SelectionLanguage="XPath" 

来源:

http://wixtoolset.org/documentation/manual/v3/xsd/util/xmlfile.html

修改

试试这个:

<util:XmlFile Id="leID2" File="[INSTALLFOLDER]Queue.exe.config" Sequence="3" Action="setValue" ElementPath="/configuration/connectionStrings/add[\[]@name='String1'[\]]/@connectionString" Value="metadata=res://*/EntityModels.String1.csdl|res://*/EntityModels.String1.ssdl|res://*/EntityModels.String1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=[DBSERVER];initial catalog=[DBNAME];User=User;Password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" Permanent="yes" />

<util:XmlFile Id="leID3" File="[INSTALLFOLDER]Queue.exe.config" Sequence="4" Action="setValue" ElementPath="/configuration/connectionStrings/add[\[]@name='String2'[\]]/@connectionString" Value="metadata=res://*/EntityModels.String2.csdl|res://*/EntityModels.String2.ssdl|res://*/EntityModels.String2.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=[DBSERVER];initial catalog=[SECONDDBNAME];User=User;Password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" Permanent="yes" />