ClickOnce 先决条件:SQL Server Express 2014 LocalDB 在哪里?

16
我正在使用Visual Studio 2013 Community版创建clickonce安装程序,用于我的WPF应用程序。该应用程序使用LocalDB。如果我手动安装sqlserver express 2014 LocalDB,则在目标计算机上可以正常工作。
但是,我想将SQL Server Express 2014 LocalDB的安装程序包括在我的clickonce部署中。
然而,当我打开先决条件对话框时,只有SQL Server 2012 Express LocalDB可用(见图)。我尝试选择"2012",但它与我要安装的mdf文件不兼容。
问题是:如何将SQL Server Express 2014 LocalDB安装程序包含为先决条件?是否有一种方法只需将MSI文件放到某个地方就可以让它起作用?还是坚持使用"2012"更容易呢? VS project prerequisites
4个回答

18
作为我在MSDN论坛上发布的帖子中所述,由于没有官方版本,我创建了自己的软件包。该软件包基本上只是SqlLocalDB2012软件包的副本,更新为指向新版本的msi文件进行下载。
我已经将引导程序软件包的所有文件放在GitHub上,以便人们不必自己创建文件。有两个版本,一个是原始版本,另一个是SP1版本。以下是创建原始版本的步骤:
  1. Create a folder SqlLocalDB2014
  2. Create an xml file in the folder called product.xml with the following contents:

    <?xml version="1.0" encoding="utf-8"?>
    <Product xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper" ProductCode="Microsoft.SqlServer.SqlLocalDB.12.0">
      <InstallChecks>
        <FileCheck
          Property="sqllocaldbVersion"
          FileName="sqlservr.exe"
          SearchPath="Microsoft SQL Server\120\LocalDB\Binn"
          SpecialFolder="ProgramFilesFolder"
        />
      </InstallChecks>
    
      <PackageFiles CopyAllPackageFiles="false">
        <PackageFile
          Name="x86\sqllocaldb.msi"
          HomeSite="sqllocaldb_32"
          PublicKey="3082010A0282010100E57C2F2D0CA9EC7AA834E04C3F7F490E0DB615AD1913DE528A26991571A962270737A5833082626C0BA3FD060D171406E6E0ADCC95960A205AA296E1E057303C5D629BC55D890CD034DFD9D8FA35EF11238BC0F9EB4AF439DA2F7110EB11B32C37A370E886173EEF2A46D08EC7B94800A137F1C7C8E7D21E6B4A2AF2C64C1D709F7CC368428E3CED811A52E33E32943D7E18F19BE44B5C11E4D6C3851E6C033073BCC9A8017D9DADD1F573F05B1A7B2F1F8B32BEB38EB53BD9F7FFF35FB3137C139357B8A05E359883A13434F2C5049FB9FE46170C91DFEF0F55F6ECCC39C96165A129EEBE11371BB76E4255C9CC35D152B303709C98349E2936A917195F0BBF0203010001"
        />
        <PackageFile
          Name="x64\sqllocaldb.msi"
          HomeSite="sqllocaldb_64"
          PublicKey="3082010A0282010100E57C2F2D0CA9EC7AA834E04C3F7F490E0DB615AD1913DE528A26991571A962270737A5833082626C0BA3FD060D171406E6E0ADCC95960A205AA296E1E057303C5D629BC55D890CD034DFD9D8FA35EF11238BC0F9EB4AF439DA2F7110EB11B32C37A370E886173EEF2A46D08EC7B94800A137F1C7C8E7D21E6B4A2AF2C64C1D709F7CC368428E3CED811A52E33E32943D7E18F19BE44B5C11E4D6C3851E6C033073BCC9A8017D9DADD1F573F05B1A7B2F1F8B32BEB38EB53BD9F7FFF35FB3137C139357B8A05E359883A13434F2C5049FB9FE46170C91DFEF0F55F6ECCC39C96165A129EEBE11371BB76E4255C9CC35D152B303709C98349E2936A917195F0BBF0203010001"
        />
      </PackageFiles>
    
      <Commands Reboot="Defer">
        <Command PackageFile="x86\sqllocaldb.msi" Arguments="IACCEPTSQLLOCALDBLICENSETERMS=YES" EstimatedInstallSeconds="90">
          <InstallConditions>
            <FailIf Property="VersionNT" Compare="ValueNotExists" String="InvalidPlatformOS" />
            <FailIf Property="VersionNT" Compare="VersionLessThan" Value="6.0.1" String="InvalidPlatformOS" />
            <FailIf Property="AdminUser" Compare="ValueEqualTo" Value="false" String="AdminRequired" />
            <BypassIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="Intel" />
            <BypassIf Property="sqllocaldbVersion" Compare="VersionGreaterThanOrEqualTo" Value="2014.120.2000.8" />
          </InstallConditions>
          <ExitCodes>
            <ExitCode Value="0" Result="Success" />
            <ExitCode Value="1641" Result="SuccessReboot" />
            <ExitCode Value="3010" Result="SuccessReboot" />
            <DefaultExitCode Result="Fail" String="GeneralFailure" FormatMessageFromSystem="true" />
          </ExitCodes>
        </Command>
        <Command PackageFile="x64\sqllocaldb.msi" Arguments="IACCEPTSQLLOCALDBLICENSETERMS=YES" EstimatedInstallSeconds="90">
          <InstallConditions>
            <BypassIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="amd64" />
            <BypassIf Property="sqllocaldbVersion" Compare="VersionGreaterThanOrEqualTo" Value="2014.120.2000.8" />
          </InstallConditions>
          <ExitCodes>
            <ExitCode Value="0" Result="Success" />
            <ExitCode Value="1641" Result="SuccessReboot" />
            <ExitCode Value="3010" Result="SuccessReboot" />
            <DefaultExitCode Result="Fail" String="GeneralFailure" FormatMessageFromSystem="true" />
          </ExitCodes>
        </Command>
      </Commands>
    </Product>
    
  3. Within the folder create another folder called en and create another xml file called package.xml

     <?xml version="1.0" encoding="utf-8"?>
     <Package Name="DisplayName" LicenseAgreement="Eula.txt" Culture="Culture" xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper">
       <PackageFiles>
         <PackageFile Name="Eula.txt" />
       </PackageFiles>
       <Strings>
         <String Name="Culture">en</String>
         <String Name="DisplayName">SQL Server 2014 Express LocalDB</String>
         <String Name="sqllocaldb_32">http://download.microsoft.com/download/E/A/E/EAE6F7FC-767A-4038-A954-49B8B05D04EB/LocalDB%2032BIT/SqlLocalDB.msi</String>
         <String Name="sqllocaldb_64">http://download.microsoft.com/download/E/A/E/EAE6F7FC-767A-4038-A954-49B8B05D04EB/LocalDB%2064BIT/SqlLocalDB.msi</String>
         <String Name="AdminRequired">You do not have the permissions required to install SQL Server 2014 Express LocalDB. Please contact your administrator.</String>
         <String Name="GeneralFailure">An error occurred attempting to install SQL Server 2014 Express LocalDB.</String>
         <String Name="InvalidPlatformOS">The current operating system version does not support SQL Server 2014 Express LocalDB.</String>
         <String Name="InvalidPlatformOSServicePack">The current operating system does not meet Service Pack level requirements for SQL Server 2014 Express LocalDB. Install the most recent Service Pack from the Microsoft download center at http://www.microsoft.com/downloads before continuing setup.</String>
       </Strings>
     </Package>
    
  4. Copy the C:\Program Files\Microsoft SQL Server\120\License Terms\License_SqlLocalDB_1033.txt file into the en folder and rename it to eula.txt.

  5. To install the package copy the folder SqlLocalDB2014 to where your other bootstrapper packages are located e.g. C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\Bootstrapper\Packages
  6. You should now be able to use the package from Visual Studio, however if you wish to have the component installed from the same location as your application then you'll need to download the two sqllocaldb.msi files specified in the package.xml file and put them in x86 and x64 folders inside the SqlLocalDb2014 folder.
  7. Lastly, this package is only for English but you may support multiple languages by adding folders for each language with package.xml and eula.txt files.

感谢您的回答。我想知道为什么 SQL Server Express 2014 LocalDB 没有作为 ClickOnce 先决条件被“开箱即用”地包含在内。使用它可能会有一些“陷阱”吗? - Angelo
@Angelo 我不确定为什么他们没有包括它,但我的感觉是clickonce 技术正在逐渐消亡,所以微软不再支持它。这个包也没有被包含在VS2015 RC中。我在自己制作这个包之前曾在 UserVoice 上提出了建议。 - kjbartel
1
请确保将文件复制到正确的“Packages”文件夹中。您的计算机上可能有几个文件夹。 对我来说,最好的是:“c:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages” 您可以在注册表\HKLM\Software\Wow6432Node\Microsoft\GenericBootstrapper\11.0中检查正确的路径。 - Istvan Heckl
@kjbartel 你好,我想知道你是如何确定PackageFile参数的,例如HomeSiteName?我需要一个类似于SqlLocalDb2017的解决方案。 - Istvan Heckl
@IstvanHeckl,它们是包.xml文件中的相同字符串。您不希望直接在product.xml文件中使用字符串,因为下载可能因语言而异。实际名称本身我认为并不重要,只要它们相同即可。我已将文件组织成单独的x84和x86文件夹,但您也可以在product.xml中重命名文件,例如sqllocaldb_x86.msi和sqllocaldb_x64.msi。 - kjbartel

5
我也遇到了完全相同的问题。我在MSDN论坛上找到了一个可能的答案,链接,它对我有效。
总结一下来自链接的答案:您需要为LocalDB 2014创建一个“启动程序”。这只是您“Microsoft SDKs目录”中包含一些特定xml文件(具有键/元数据和eula文本文件)的文件夹。链接中提供了这些xml文件的内容。重启Visual Studio后,“Sql Express 2014 LocalDB”将与所有其他先决条件一起出现,并且可以添加到ClickOnce依赖项中。

4

解决Localdb2017的方法

将SqlLocalDB2017文件夹复制到正确的位置,例如:c:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages,并重新启动Visual Studio。


2
这里是一个简单而完整的说明,教你如何在Visual Studio中添加SqlLocalDB 2014 ClickOnce Bootstraper。如果你想包含sqllocalDB安装文件,只需从package.xml文件中的链接下载即可。但似乎sqllocaldb_x64.msi有问题,在x64 Windows上无法安装(已在Windows 7 x64 sp1上测试)。最初的回答请参考这里

https://github.com/heckl/SqlLocalDB2017-Bootstrapper 这个地址无法访问,我需要在Visual Studio 2019中安装Local db 2017包。 - Steve

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接