2013-04-11 77 views
0

是否有可能,如果是的話如何在WiX安裝項目中從多個屬性創建單個值?WiX:將值設置爲多個屬性的組合

具體來說,我有一些對話是這樣的...

<Dialog Id="ConnectionStringDlg" Width="370" 
     Height="270" Title="Database Settings - [ProductName]" NoMinimize="yes"> 
    <!-- Connection String --> 
    <Control Id="TitleLabel" Type="Text" X="45" Y="60" Width="100" Height="15" TabSkip="yes" Text="Connection String" /> 
    <Control Id="DSLabel" Type="Text" X="45" Y="77" 
     Width="100" Height="15" TabSkip="no" Text="&amp;Data Source: " /> 
    <Control Id="DSEdit" Type="Edit" X="45" Y="92" 
     Width="220" Height="18" Property="CONNECTION_STRING_DS" Text="{200}" /> 
    <Control Id="ICLabel" Type="Text" X="45" Y="107" 
     Width="100" Height="15" TabSkip="no" Text="&amp;Initial Catalog: " /> 
    <Control Id="ICEdit" Type="Edit" X="45" Y="122" 
     Width="220" Height="18" Property="CONNECTION_STRING_IC" Text="{200}" /> 
    <Control Id="UIDLabel" Type="Text" X="45" Y="137" 
     Width="100" Height="15" TabSkip="no" Text="&amp;User ID: " /> 
    <Control Id="UIDEdit" Type="Edit" X="45" Y="152" 
     Width="220" Height="18" Property="CONNECTION_STRING_UI" Text="{200}" /> 
    <Control Id="PassLabel" Type="Text" X="45" Y="167" 
     Width="100" Height="15" TabSkip="no" Text="&amp;Password: " /> 
    <Control Id="PassEdit" Type="Edit" X="45" Y="182" Password="yes" 
     Width="220" Height="18" Property="CONNECTION_STRING_PASS" Text="{200}" /> 
    <!-- Back button --> 
    <!--<Control Id="Back" Type="PushButton" X="180" Y="243" 
      Width="56" Height="17" Text="&amp;Back"> 
     <Publish Event="NewDialog" Value="PoolSettingsDlg">1</Publish> 
    </Control>--> 
    <Control Id="Next" Type="PushButton" X="236" Y="243" 
      Width="56" Height="17" Default="yes" Text="&amp;Next"> 
     <Publish Event="NewDialog" Value="CustomizeDlg"> 
     <!--if settings are correct, allow next dialog--> 
     <![CDATA[CONNECTION_STRING <> ""]]> 
     </Publish> 
    </Control> 
    <Control Id="Cancel" Type="PushButton" X="304" Y="243" 
     Width="56" Height="17" Cancel="yes" Text="Cancel"> 
     <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish> 
    </Control> 
    <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" 
     Width="370" Height="44" TabSkip="no" Text="WixUI_Bmp_Banner" /> 
    <Control Id="Description" Type="Text" X="25" Y="23" 
      Width="280" Height="15" Transparent="yes" NoPrefix="yes"> 
     <Text>Please enter database configuration</Text> 
    </Control> 
    <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" /> 
    <Control Id="Title" Type="Text" X="15" Y="6" 
      Width="200" Height="15" Transparent="yes" NoPrefix="yes"> 
     <Text>{\WixUI_Font_Title}Database Settings</Text> 
    </Control> 
    <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" /> 
    </Dialog> 

裏面我是用得到來自用戶友好的方式最終用戶的連接字符串信息。然後我在使用安裝時web.config文件設置這個值...

<Component Id="cmp623DDF82F0F7645ADAAF0E7573713162" Guid="{8CFDC325-BC71-4A2F-AB22-68B0AE56C98B}"> 
       <File Id="fil5B0B918C0DAF7B2ECC5EB9C7CC0B9FFC" KeyPath="yes" Source="Publish\Web.config" /> 
       <util:XmlFile Id="ModifyConnectionString" 
        Action="setValue" 
        Permanent="yes" 
        ElementPath="//configuration/connectionStrings/add[\[]@name='RawConnection'[\]]" 
        Name="connectionString" 
        File="[#fil5B0B918C0DAF7B2ECC5EB9C7CC0B9FFC]" 
        Value="[CONNECTION_STRING]" 
        SelectionLanguage="XSLPattern" 
        Sequence="1"/> 
      </Component> 

我的問題是,我怎麼可以設置通過使從該對話框中設置多個屬性的複合連接字符串值?

回答

0

您可以使用MSI Community extensions這個,因爲它爲您提供了一個不錯的界面,並將爲您設置字符串格式。

但是,如果你想建立起來手動你可以做字符串建築在Value屬性:

<util:XmlFile Id="ModifyConnectionString" 
       Action="setValue" 
       Permanent="yes" 
       ElementPath="//configuration/connectionStrings/add[\[]@name='RawConnection'[\]]" 
       Name="connectionString" 
       File="[#fil5B0B918C0DAF7B2ECC5EB9C7CC0B9FFC]" 
       Value='Server=[CONNECTION_STRING_DS];Database=[CONNECTION_STRING_IC];User Id=[CONNECTION_STRING_UI];Password=[CONNECTION_STRING_PASS];' 
       SelectionLanguage="XSLPattern" 
       Sequence="1"/>  

另外,如果你需要設置一個屬性在多個地方使用您可以使用CustomAction或SetProperty元素(他們都做同樣的事情):

<CustomAction Id='SetConnectionString' 
       Property='CONNECTION_STRING' 
       Before='ExecXmlFile' 
       Value='Server=[CONNECTION_STRING_DS];Database=[CONNECTION_STRING_IC];User Id=[CONNECTION_STRING_UI];Password=[CONNECTION_STRING_PASS];' /> 

<SetProperty Id='CONNECTION_STRING' 
      Before='ExecXmlFile' 
      Value='Server=[CONNECTION_STRING_DS];Database=[CONNECTION_STRING_IC];User Id=[CONNECTION_STRING_UI];Password=[CONNECTION_STRING_PASS];' /> 
+0

我做了你對value屬性的建議,它的效果很好。將來我會考慮使用社區擴展。謝謝您的幫助。 – 2013-04-11 17:43:28