簡體   English   中英

如何使用MSI中包含的xml文件在wix工具集中填充文本框?

[英]how to populate a text box in wix toolset using xml file included in the msi?

我的安裝程序中包含一個名為App.xml的文件(將在客戶端計算機上安裝),我要從中加載數據並將其顯示給用戶,以便他可以操縱將要安裝的內容/如何使用系統。

我已經嘗試過使用Xml文件擴展名/自定義操作(在線檢查),但找不到加載嵌入在安裝程序中的源文件的方法。

我的文件是: <App> <Text>bla bla</text></App>

我希望安裝程序顯示“ bla bla”文本,用戶可以更改它,以后可以像平常一樣通過擴展名保存它。

謝謝!

這將是您必須通過自定義操作提供的自定義功能。 從高級設計來看,我看到您在命令行中傳遞了xml文件的路徑。 在運行時,您的自定義操作將讀取文件中的節點並設置文本框正在使用的適當屬性。

我遇到了類似的問題。 四處尋找一個解決方案,讓您的InstallUISequence過程中使用的XML文件,在安裝文件之前,它看起來像你需要描述一個自定義表添加到您的WiX的定義在這里

基本上,您在.wxs文件中創建CustomTable元素,例如:

<CustomTable Id="App">
    <Text>bla bla</Text>
</CustomTable>

然后,您可以通過創建查看查詢以查找所需的屬性,通過ac#自定義操作從中讀取信息:

using (View view = session.Database.OpenView("SELECT 'Text' FROM 'App'"))
{
    view.Execute();
    // access view properties and turn them into some object you want to manipulate
}

對於該視圖對象將要擁有的內容,我會有些無知,但是我知道您可以遍歷其記錄或獲取各個列,在屬性中四處瀏覽最終會為您找到所需的值。 下一步是使用值填充組合框元素

<Control Id="DropdownSelectLabel" Type="Text" X="50" Y="65" Width="200" Height="15" TabSkip="no" Text="&amp;Select a value:">
</Control>
<Control Id="DropdownSelect" Type="ComboBox" Height="16" Width="200" X="60" Y="80" Property="MY_PROPERTY_KEY" ComboList="yes">
    <ComboBox Property="MY_PROPERTY_KEY">
        <!-- Optional prepopulate value-->
        <ListItem Text="[dummy_text]" Value="[dummy_value]" />
    </ComboBox>
</Control>

我正在通過Visual Studio構建的InstallUISequence中運行的自定義c#操作填充它

<!-- Custom action for populating the combobox -->
<CustomAction Id="CA_PopulateComboBox" BinaryKey="BIN_CustomActions" DllEntry="PopulateComboBox" Execute="firstSequence" />

<!-- Binaries for the custom action -->
<Binary Id="BIN_CustomActions" SourceFile="..\PATH-TO-YOUR-CUSTOM-ACTION-BIN-RELEASE.CA.dll" />

<!-- Schedule the custom action -->
<InstallUISequence>
    <Custom Action="CA_PopulateComboBox" Before="LaunchConditions" />
</InstallUISequence>

自定義操作如下所示:

public class CustomActions
{
    /// <summary>
    /// Populates the ComboBox UI Element.
    /// </summary>
    /// <param name="session">The session.</param>
    [CustomAction]
    public static void PopulateComboBox(Session session)
    {
        session.Log("Populating the combobox with certificates");

        // Clear the combobox (unecessary if it starting empty)
        View view = session.Database.OpenView("DELETE FROM ComboBox WHERE ComboBox.Property='MY_PROPERTY_KEY'");
        view.Execute();

        view = session.Database.OpenView("SELECT * FROM ComboBox");
        view.Execute();

        List<ComboBoxRecordWrapper> valuesToAdd = PopulateValuesObjects(session); // Add the logic to read your xml values from the session object here

        var index = 1;
        foreach (ComboBoxRecordWrapper valueObject in valuesToAdd)
        {
            session.Log($"Adding value to the combobox: {valueObject.Text} - {valueObject.Value} {Environment.NewLine}Order: {valueObject.Order}");

            view.Modify(ViewModifyMode.InsertTemporary, recordWrapper.ToRecord());
            view.Execute();
            index++;
        }

        view.Close();
    }
}

/// <summary>
/// Class ComboBoxRecordWrapper. Wraps objects that should be represented in a combobox element in the installer
/// </summary>
public class ComboBoxRecordWrapper
{
    /// <summary>
    /// Gets or sets the property that this element's value will be stored as if the element is selected
    /// </summary>
    /// <value>The property.</value>
    public string Property { get; set; }

    /// <summary>
    /// Gets or sets the order that this element appears in the combobox
    /// </summary>
    /// <value>The order.</value>
    public int Order { get; set; }

    /// <summary>
    /// Gets or sets the value of the combobox option. This is what will be available to the UI element as a returned value
    /// </summary>
    /// <value>The value.</value>
    public string Value { get; set; }

    /// <summary>
    /// Gets or sets the text that will be displayed for this element
    /// </summary>
    /// <value>The text.</value>
    public string Text { get; set; }

    /// <summary>
    /// Initializes a new instance of the <see cref="ComboBoxRecordWrapper"/> class.
    /// </summary>
    /// <param name="property">The property.</param>
    /// <param name="order">The order.</param>
    /// <param name="value">The value.</param>
    /// <param name="text">The text.</param>
    public ComboBoxRecordWrapper(string property, int order, string value, string text)
    {
        this.Property = property;
        this.Order = order;
        this.Value = value;
        this.Text = string.IsNullOrEmpty(text) ? value : text;
    }

    /// <summary>
    /// Converts to a record to add to the MSI database.
    /// </summary>
    /// <returns>Record.</returns>
    public Record ToRecord()
    {
        var record = new Record(4);
        record.SetString(1, this.Property);
        record.SetInteger(2, this.Order);
        record.SetString(3, this.Value);
        record.SetString(4, this.Text);
        return record;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM