WiX:安装前读取文件内容

时间:2019-06-03 08:50:07

标签: c# wix

我想读取WiX中文件的内容,以便可以在安装过程中使用它们[它们是我要通过自定义操作执行的SQL脚本]

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="INSTALLFOLDER">
            <Component Id="cmp35BC97AC12F21A6F6154759C2D9B5430" Guid="*">
                <File Id="filDEDB241BDDF1A0CD0B001190398F5F5F" KeyPath="yes" Source="SourceDir\TestScript - Copy.sql" />
            </Component>
            <Component Id="cmp221D9003B2C58612888DBC0D1CEBC730" Guid="*">
                <File Id="filF6EA2F11A51AF10E1517FFB9152307EE" KeyPath="yes" Source="SourceDir\TestScript.sql" />
            </Component>
        </DirectoryRef>
    </Fragment>
    <Fragment>
        <ComponentGroup Id="AgentX.Database.Installer">
            <ComponentRef Id="cmp35BC97AC12F21A6F6154759C2D9B5430" />
            <ComponentRef Id="cmp221D9003B2C58612888DBC0D1CEBC730" />
        </ComponentGroup>
    </Fragment>
</Wix>

我已使用以下代码检查文件的内容:

var fileView = session.Database.OpenView("SELECT * FROM File");
            fileView.Execute(null);

            foreach (Record fileRec in fileView)
            {

                session.Log("\t{0}", fileRec["FileName"]);
            }

我想读取嵌入在MSI中的sql文件。

1 个答案:

答案 0 :(得分:0)

SqlScript :我几乎从不使用此功能,但是WiX具有SqlScript Element,应该可以为您完成这项工作。我一直想知道SQL脚本是否应该由应用程序而不是安装程序运行,但这是另一次讨论。

代码段 ({from WiX tutorial-downloadable sample朝底部):

<Binary Id='CreateTable' SourceFile='CreateTable.sql' />

<..>

<Component Id='SqlComponent' Guid='YOURGUID-D8C7-4102-BA84-9702188FA316'>
  <sql:SqlDatabase Id='SqlDatabase' Database='Foobar' User='SQLUser' Server='[SQLSERVER]'
    CreateOnInstall='yes' DropOnUninstall='yes' ContinueOnError='yes'>
    <sql:SqlScript Id='CreateTable' BinaryKey='CreateTable' ExecuteOnInstall='yes' />
  </sql:SqlDatabase>
</Component>

链接

SQL