0

是否有可能,如果可以,我如何从 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>

我的问题是,如何通过从对话框中设置的多个属性进行组合来设置连接字符串值?

4

1 回答 1

0

您可以为此使用MSI 社区扩展,因为它为您提供了一个很好的界面,并会为您格式化字符串。

但是,如果您想手动构建它,您可以在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];' />
于 2013-04-11T16:50:21.333 回答