19

我正在开发 WPF 应用程序,并使用 WiX 作为安装程序。

我想开始使用 SQL Express 2012,但想先解决安装程序问题。

我正在寻找使用 WiX 检测、引导、安装、升级和卸载 SQL Express 2012 的完整示例(尽管部分也很有用)。

此外,到目前为止,我在网络上发现的大多数检测逻辑都使用注册表项。但是,Microsoft 建议改用 WMI(请参阅http://blogs.msdn.com/b/sqlexpress/archive/2006/07/29/faq-detecting-sql-server-2005-using-wmi.aspx)。使用 WiX 可以吗?

4

2 回答 2

25

这就是我所拥有的,希望对您有所帮助:

<?define ServerInstall="SomeCondition" ?>

<?define InstanceName = "YOUR_INSTANCE" ?>
<?define SqlWebLink = http://download.microsoft.com/download/5/2/9/529FEF7B-2EFB-439E-A2D1-A1533227CD69/SQLEXPR_x86_ENU.exe ?>

<Variable Name="SqlVariable" Type="string" Value="/SAPWD=some_password" Hidden="yes" />

<!-- Read SQL Server keys to find current instance and version -->
<util:RegistrySearch
  Id="SqlInstanceKeyFound"
  Root="HKLM" Key="SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL" Value="$(var.InstanceName)"
  Result="exists" Variable="SqlInstanceKeyFound" />
<util:RegistrySearch
  Id="SqlInstanceKey"
  Root="HKLM" Key="SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL" Value="$(var.InstanceName)"
  Variable="SqlInstanceKey" After="SqlInstanceKeyFound" Condition="SqlInstanceKeyFound" />
<util:RegistrySearch
  Id="SqlInstanceFound"
  Root="HKLM" Key="SOFTWARE\Microsoft\Microsoft SQL Server\[SqlInstanceKey]"
  Result="exists" Variable="SqlInstanceFound" After="SqlInstanceKey" Condition="SqlInstanceKeyFound" />
<util:RegistrySearch
  Id="SqlVersion"
  Root="HKLM" Key="SOFTWARE\Microsoft\Microsoft SQL Server\[SqlInstanceKey]\Setup" Value="Version"
  Variable="SqlVersion" After="SqlInstanceKey" Condition="SqlInstanceFound" />

<PackageGroup Id="Sql2012Express">
  <!--
    SQL Server 2012 Express - Install new instance
    http://msdn.microsoft.com/en-us/library/ms144259.aspx
    SQL Server Express requires WIndows Installer 4.5
    RepairCommand="/ACTION=Repair /INSTANCENAME=$(var.InstanceName) /Q /HIDECONSOLE"
  -->
  <ExePackage Id="Sql2012Express"
    DisplayName="SQL Server 2012 Express"
    Cache="yes"
    Compressed="no"
    PerMachine="yes"
    Permanent="no"
    Vital="yes"
    Name="Redist\SQLEXPR_x86_ENU.exe"
    SourceFile="..\Packages\SQLEXPR_x86_ENU.exe"
    DownloadUrl="$(var.SqlWebLink)"
    InstallCommand="/ACTION=Install /INSTANCENAME=$(var.InstanceName) /FEATURES=SQL /SECURITYMODE=SQL [SqlVariable] /TCPENABLED=1 /SQLSVCACCOUNT=&quot;NT AUTHORITY\NETWORK SERVICE&quot; /SQLSVCSTARTUPTYPE=Manual /SQLSYSADMINACCOUNTS=BUILTIN\Administrators /ADDCURRENTUSERASSQLADMIN=FALSE /Q /HIDECONSOLE /SkipRules=RebootRequiredCheck /IAcceptSQLServerLicenseTerms"
    UninstallCommand="/Action=Uninstall /INSTANCENAME=$(var.InstanceName) /FEATURES=SQL /Q /HIDECONSOLE"
    DetectCondition="SqlInstanceFound"
    InstallCondition="$(var.ServerInstall)">
    <ExitCode Value ="3010" Behavior="forceReboot" />
    <dep:Provides DisplayName="Net2 SQL Server 2012 Express" Key="SQLServer2012Express,$(var.InstanceName)" Version="11.0.3000.0" />
  </ExePackage>

  <!--
    SQL Server 2012 Express - Upgrade existing pre-SQL 2012 instance
  -->
  <ExePackage Id="Sql2012ExpressUpgrade"
    DisplayName="SQL Server 2012 Express Upgrade"
    Cache="no"
    Compressed="no"
    PerMachine="yes"
    Permanent="yes"
    Vital="yes"
    Name="Redist\SQLEXPR_x86_ENU.exe"
    SourceFile="..\Packages\SQLEXPR_x86_ENU.exe"
    DownloadUrl="$(var.SqlWebLink)"
    InstallCommand="/ACTION=Upgrade /INSTANCENAME=$(var.InstanceName) /Q /HIDECONSOLE /SkipRules=RebootRequiredCheck /IAcceptSQLServerLicenseTerms"
    DetectCondition="NOT (SqlInstanceFound AND (SqlVersion &lt; v11.0.0.0))"
    InstallCondition="$(var.ServerInstall)">
    <ExitCode Value ="3010" Behavior="forceReboot" />
  </ExePackage>

  <!--
    SQL Server 2012 SP1 Express - Upgrade existing SQL 2012 instance to SP1
  -->
  <ExePackage Id="Sql2012ExpressEditionUpgrade"
    DisplayName="SQL Server 2012 SP1 Express Patch"
    Cache="no"
    Compressed="no"
    PerMachine="yes"
    Permanent="yes"
    Vital="yes"
    Name="Redist\SQLEXPR_x86_ENU.exe"
    SourceFile="..\Packages\SQLEXPR_x86_ENU.exe"
    DownloadUrl="$(var.SqlWebLink)"
    InstallCommand="/ACTION=Patch /INSTANCENAME=$(var.InstanceName) /Q /HIDECONSOLE /SkipRules=RebootRequiredCheck /IAcceptSQLServerLicenseTerms"
    DetectCondition="NOT (SqlInstanceFound AND (SqlVersion &gt; v11.0.0.0) AND (SqlVersion &lt; v11.0.3000.0))"
    InstallCondition="$(var.ServerInstall)">
    <ExitCode Value ="3010" Behavior="forceReboot" />
  </ExePackage>

您需要更改安装命令以符合您的要求。

于 2013-09-25T16:14:38.417 回答
1

在以下 2 项更改之前,没有任何建议对我有用:

  1. 设置 util:RegistrySearch/@Win64 属性值为“yes”(默认为“no”,32位系统也可以)

  2. 完全删除 ExePackage/@DetectCondition 属性(不知道原因)

下面是工作示例:

    <util:RegistrySearch Id="SqlInstanceKeyFoundSearch"
                         Root="HKLM"
                         Key="SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL"
                         Value="SQLEXPRESSENGINE"
                         Result="exists"
                         Variable="SqlInstanceKeyFound"
                         Win64="yes" />

    <PackageGroup Id="SQLServerExpress">
        <ExePackage Compressed="no"
                    DisplayName="Installing SQL Server Express 2014"
                    PerMachine="yes"
                    Cache="yes"
                    Vital="yes"
                    Permanent="no"
                    InstallCommand='/IACCEPTSQLSERVERLICENSETERMS /HIDECONSOLE /INSTANCEID="$(var.InstanceName)" /ACTION="Install" /FEATURES=SQLENGINE /HELP="False" /INDICATEPROGRESS="False" /QUIET="True" /QUIETSIMPLE="False" /ERRORREPORTING="False" /SQMREPORTING="False" /INSTANCENAME="$(var.InstanceName)" /AGTSVCSTARTUPTYPE="Manual" /ISSVCSTARTUPTYPE="Automatic" /ISSVCACCOUNT="NT AUTHORITY\NetworkService" /ASSVCSTARTUPTYPE="Automatic" /ASCOLLATION="Latin1_General_CI_AS" /ASDATADIR="Data" /ASLOGDIR="Log" /ASBACKUPDIR="Backup" /ASTEMPDIR="Temp" /ASCONFIGDIR="Config" /ASPROVIDERMSOLAP="1" /SQLSVCSTARTUPTYPE="Automatic" /FILESTREAMLEVEL="0" /ENABLERANU="True" /SQLCOLLATION="SQL_Latin1_General_CP1_CI_AS" /SQLSVCACCOUNT="NT AUTHORITY\NETWORK SERVICE" /ADDCURRENTUSERASSQLADMIN="True" /TCPENABLED="0" /NPENABLED="0" /BROWSERSVCSTARTUPTYPE="Disabled" /RSSVCSTARTUPTYPE="Automatic" /RSINSTALLMODE="FilesOnlyMode" /SECURITYMODE=SQL /SAPWD="tomsoN_admin_1032"'
                    UninstallCommand='/Action=Uninstall /INSTANCENAME="$(var.InstanceName)" /FEATURES=SQLENGINE /QUIET="True" /HIDECONSOLE'
                    InstallCondition="NOT SqlInstanceKeyFound"
                    DownloadUrl="https://download.microsoft.com/download/1/5/6/156992E6-F7C7-4E55-833D-249BD2348138/ENU/x64/SQLEXPR_x64_ENU.exe"
                    Name="SQLEXPR_x64_ENU.exe">
            <RemotePayload CertificatePublicKey="B78FE7F6917E1BC5F4A9C77BA3D555A0E807B9E0" CertificateThumbprint="67B1757863E3EFF760EA9EBB02849AF07D3A8080" Description="Microsoft SQL Server 2014  Express SP1" Hash="0C90C147A1C2A550165C9301AE7A6C604E318E51" ProductName="Microsoft SQL Server 2014  Express SP1" Size="318752832" Version="12.1.4100.1" />
        </ExePackage>

    </PackageGroup>
于 2016-04-28T14:40:31.013 回答