[Visual Studio] 咦!?專案發佈的Prerequisites裡面找不到SQL Server 2008 R2 Express !? 那就自己加吧!!

這幾天在玩Visual Studio 2010中的Setup Project的時候,驚然發覺,咦!!?內建的Prerequisites列表裡面只有SQL Server 2008 Express ,但是沒有SQL Server 2008 R2 Express耶!? 可是我要發佈的專案用的資料庫是SQL Server 2008 R2 Express版的,又不想現在把已經建好的SQL Server 2008 R2 Express 打回SQL Server 2008 Express,嘖嘖~~只好自己動手加囉!!

 

這幾天在玩Visual Studio 2010中的Setup Project的時候,驚然發覺,咦!!?內建的Prerequisites列表裡面只有SQL Server 2008 Express ,但是沒有SQL Server 2008 R2 Express耶!? 可是我要發佈的專案用的資料庫是SQL Server 2008 R2 Express版的,又不想現在把已經建好的SQL Server 2008 R2 Express 打回SQL Server 2008 Express,嘖嘖~~只好自己動手加囉!!

 

預設的選項裡面就是沒有SQL Server 2008 R2 Express....

image

 

Step 1. 複製SQL Server 2008 Express 的Bootstrapper Packages

由於Visual Studio 2010的Prerequisites中的項目是由電腦中現存的Bootstrapper Packages互相關聯的,所以只要從Bootstrapper Packages下手就行啦!!

首先請使用檔案總管瀏覽到Bootstrapper Packages所在的資料夾,以我的環境(Windows 7 x64搭配Visual Studio 2010英文版)為例,預設的路徑是C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages

image

有沒有看到 SqlExpress2008那個資料夾!? 對~就是它!! 請使用血輪眼將整個資料夾拷貝一份,並且改名為SqlExpress2008R2。

image

 

Step 2. 修改SQL Server 2008 R2 Express Bootstrapper Packages中的設定檔

SqlExpress2008R2資料夾中有一個product.xml

image

請以下面的內容取代掉原來的檔案內容:

product.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- SQL Express 2008 R2 VS Bootstrapper : product.xml : Language neutral information -->
<Product xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper" ProductCode="Microsoft.Sql.Server.Express.10.5.UnOfficial">
  <RelatedProducts>
    <EitherProducts>
      <DependsOnProduct Code=".NETFramework,Version=v4.0" />
      <DependsOnProduct Code="Microsoft.Net.Framework.3.5.SP1" />
    </EitherProducts>
    <DependsOnProduct Code="Microsoft.Windows.Installer.4.5" />
    <IncludesProduct Code="Microsoft.Sql.Server.Express.1.0" />
    <IncludesProduct Code="Microsoft.Sql.Server.Express.9.2" />
    <IncludesProduct Code="Microsoft.Sql.Server.Express.10.0" />
  </RelatedProducts>
  <PackageFiles>
    <PackageFile Name="SqlExpressChk.exe" />
  </PackageFiles>
</Product>

SqlExpress2008R2\en資料夾下有一個package.xml

image

請以下面的內容取代掉原來的內容:

package.xml

<?xml version="1.0" encoding="utf-8" ?>
<Package
	xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper"
	Name="DisplayName"
	Culture="Culture"
	LicenseAgreement="eula.rtf">

  <PackageFiles CopyAllPackageFiles="false">
    <PackageFile Name="SQLEXPR32_x86_ENU.EXE" HomeSite="SqlExpr32Exe"/>
    <PackageFile Name="SQLEXPR_x64_ENU.EXE" HomeSite="SqlExpr64Exe"/>
    <PackageFile Name="eula.rtf"/>
  </PackageFiles>

  <InstallChecks>
    <ExternalCheck Property="SQLExpressChk" PackageFile="SqlExpressChk.exe" Arguments="10.50.1600 1033"/>
  </InstallChecks>

  <Commands Reboot="Defer">

    <!-- Defines a new installation (x86) -->
    <Command PackageFile="SQLEXPR32_x86_ENU.EXE"
				 Arguments='/q /hideconsole /action=Install /features=SQL /instancename=SQLEXPRESS /enableranu=1 /sqlsvcaccount="NT Authority\Network Service" /AddCurrentUserAsSqlAdmin /skiprules=RebootRequiredCheck /IAcceptSQLServerLicenseTerms'
				 EstimatedInstalledBytes="225000000"
				 EstimatedInstallSeconds="420">
      <InstallConditions>
        <FailIf Property="VersionNT" Compare="ValueNotExists" String="GeneralFailure"/>
        <FailIf Property="VersionNT" Compare="VersionLessThan" Value="5.1.2" String="InvalidPlatformXP"/>
        <FailIf Property="VersionNT" Compare="VersionEqualTo" Value="5.2.0" String="InvalidPlatform2K3"/>
        <FailIf Property="VersionNT" Compare="VersionEqualTo" Value="5.2.1" String="InvalidPlatform2K3"/>
        <FailIf Property="AdminUser" Compare="ValueEqualTo" Value="false" String="AdminRequired"/>
        <FailIf Property="SQLExpressChk" Compare="ValueEqualTo" Value="-1" String="InvalidUpgradeNotExpress"/>
        <FailIf Property="SQLExpressChk" Compare="ValueEqualTo" Value="-2" String="InvalidUpgradeNotExpressCore"/>
        <FailIf Property="SQLExpressChk" Compare="ValueEqualTo" Value="-3" String="InvalidUpgradeLanguage"/>
        <FailIf Property="SQLExpressChk" Compare="ValueEqualTo" Value="-4" String="InvalidUpgradeWoW"/>
        <FailIf Property="SQLExpressChk" Compare="ValueLessThan" Value="-4" String="GeneralFailure"/>
        <BypassIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="Intel"/>
        <BypassIf Property="SQLExpressChk" Compare="ValueNotEqualTo" Value="1"/>
      </InstallConditions>
      <ExitCodes>
        <ExitCode Value="0" Result="Success"/>
        <ExitCode Value="1641" Result="SuccessReboot"/>
        <ExitCode Value="3010" Result="SuccessReboot"/>
        <!-- 0x84BE0BC2 (1214,3010) -->
        <ExitCode Value="-2067919934" Result="FailReboot"/>
        <!-- 0x84C10BC2 (1217,3010) -->
        <ExitCode Value="-2067723326" Result="FailReboot"/>
        <!-- 0x84BE0007 (1214,7) -->
        <ExitCode Value="-2067922937" Result="Fail" String="AdminRequired"/>
        <!-- 0x84C4001F (1220,31) -->
        <ExitCode Value="-2067529697" Result="Fail" String="AdminRequired"/>
        <!-- 0x84BE0001 (1214,1)-->
        <ExitCode Value="-2067922943" Result="Fail" String="InvalidPlatformOSServicePacks"/>
        <!-- 0x84C4000B (1220,11) -->
        <ExitCode Value="-2067529717" Result="Fail" String="AnotherInstanceRunning"/>
        <!-- 0x84BE01F8 (1214,504) -->
        <ExitCode Value="-2067922440" Result="Fail" String="BetaComponentsFailure"/>
        <!-- 0x84BE01FA (1214,506) -->
        <ExitCode Value="-2067922438" Result="Fail" String="BetaComponentsFailure"/>
        <!-- 0x84BE0202 (1214,514) -->
        <ExitCode Value="-2067922430" Result="Fail" String="InvalidPlatformArchitecture"/>
        <!-- 0x84BE0203 (1214,515) -->
        <ExitCode Value="-2067922429" Result="Fail" String="InvalidPlatformArchitecture"/>
        <ExitCode Value="216" Result="Fail" String="InvalidPlatformArchitecture"/>
        <DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />
      </ExitCodes>
    </Command>

    <!-- Defines an upgrade installation (x86) -->
    <Command PackageFile="SQLEXPR32_x86_ENU.EXE"
				 Arguments="/q /hideconsole /action=Upgrade /instancename=SQLEXPRESS /skiprules=RebootRequiredCheck /IAcceptSQLServerLicenseTerms"
				 EstimatedInstalledBytes="225000000"
				 EstimatedInstallSeconds="420">
      <InstallConditions>
        <BypassIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="Intel"/>
        <BypassIf Property="SQLExpressChk" Compare="ValueNotEqualTo" Value="2"/>
      </InstallConditions>
      <ExitCodes>
        <ExitCode Value="0" Result="Success"/>
        <ExitCode Value="1641" Result="SuccessReboot"/>
        <ExitCode Value="3010" Result="SuccessReboot"/>
        <!-- 0x84BE0BC2 (1214,3010) -->
        <ExitCode Value="-2067919934" Result="FailReboot"/>
        <!-- 0x84C10BC2 (1217,3010) -->
        <ExitCode Value="-2067723326" Result="FailReboot"/>
        <!-- 0x84BE0007 (1214,7) -->
        <ExitCode Value="-2067922937" Result="Fail" String="AdminRequired"/>
        <!-- 0x84C4001F (1220,31) -->
        <ExitCode Value="-2067529697" Result="Fail" String="AdminRequired"/>
        <!-- 0x84BE0001 (1214,1)-->
        <ExitCode Value="-2067922943" Result="Fail" String="InvalidPlatformOSServicePacks"/>
        <!-- 0x84C4000B (1220,11) -->
        <ExitCode Value="-2067529717" Result="Fail" String="AnotherInstanceRunning"/>
        <!-- 0x84BE01F8 (1214,504) -->
        <ExitCode Value="-2067922440" Result="Fail" String="BetaComponentsFailure"/>
        <!-- 0x84BE01FA (1214,506) -->
        <ExitCode Value="-2067922438" Result="Fail" String="BetaComponentsFailure"/>
        <!-- 0x84BE0202 (1214,514) -->
        <ExitCode Value="-2067922430" Result="Fail" String="InvalidPlatformArchitecture"/>
        <!-- 0x84BE0203 (1214,515) -->
        <ExitCode Value="-2067922429" Result="Fail" String="InvalidPlatformArchitecture"/>
        <ExitCode Value="216" Result="Fail" String="InvalidPlatformArchitecture"/>
        <DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />
      </ExitCodes>
    </Command>

    <!-- Defines a new installation (amd64) -->
    <Command PackageFile="SQLEXPR_x64_ENU.EXE"
				 Arguments='/q /hideconsole /action=Install /features=SQL /instancename=SQLEXPRESS /enableranu=1 /sqlsvcaccount="NT Authority\Network Service" /AddCurrentUserAsSqlAdmin /skiprules=RebootRequiredCheck /IAcceptSQLServerLicenseTerms'
				 EstimatedInstalledBytes="225000000"
				 EstimatedInstallSeconds="420">
      <InstallConditions>
        <BypassIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="amd64"/>
        <BypassIf Property="SQLExpressChk" Compare="ValueNotEqualTo" Value="1"/>
      </InstallConditions>
      <ExitCodes>
        <ExitCode Value="0" Result="Success"/>
        <ExitCode Value="1641" Result="SuccessReboot"/>
        <ExitCode Value="3010" Result="SuccessReboot"/>
        <!-- 0x84BE0BC2 (1214,3010) -->
        <ExitCode Value="-2067919934" Result="FailReboot"/>
        <!-- 0x84C10BC2 (1217,3010) -->
        <ExitCode Value="-2067723326" Result="FailReboot"/>
        <!-- 0x84BE0007 (1214,7) -->
        <ExitCode Value="-2067922937" Result="Fail" String="AdminRequired"/>
        <!-- 0x84C4001F (1220,31) -->
        <ExitCode Value="-2067529697" Result="Fail" String="AdminRequired"/>
        <!-- 0x84BE0001 (1214,1)-->
        <ExitCode Value="-2067922943" Result="Fail" String="InvalidPlatformOSServicePacks"/>
        <!-- 0x84C4000B (1220,11) -->
        <ExitCode Value="-2067529717" Result="Fail" String="AnotherInstanceRunning"/>
        <!-- 0x84BE01F8 (1214,504) -->
        <ExitCode Value="-2067922440" Result="Fail" String="BetaComponentsFailure"/>
        <!-- 0x84BE01FA (1214,506) -->
        <ExitCode Value="-2067922438" Result="Fail" String="BetaComponentsFailure"/>
        <!-- 0x84BE0202 (1214,514) -->
        <ExitCode Value="-2067922430" Result="Fail" String="InvalidPlatformArchitecture"/>
        <!-- 0x84BE0203 (1214,515) -->
        <ExitCode Value="-2067922429" Result="Fail" String="InvalidPlatformArchitecture"/>
        <ExitCode Value="216" Result="Fail" String="InvalidPlatformArchitecture"/>
        <DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />
      </ExitCodes>
    </Command>

    <!-- Defines an upgrade installation (amd64) -->
    <Command PackageFile="SQLEXPR_x64_ENU.EXE"
				 Arguments="/q /hideconsole /action=Upgrade /instancename=SQLEXPRESS /skiprules=RebootRequiredCheck /IAcceptSQLServerLicenseTerms"
				 EstimatedInstalledBytes="225000000"
				 EstimatedInstallSeconds="420">
      <InstallConditions>
        <BypassIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="amd64"/>
        <BypassIf Property="SQLExpressChk" Compare="ValueNotEqualTo" Value="2"/>
      </InstallConditions>
      <ExitCodes>
        <ExitCode Value="0" Result="Success"/>
        <ExitCode Value="1641" Result="SuccessReboot"/>
        <ExitCode Value="3010" Result="SuccessReboot"/>
        <!-- 0x84BE0BC2 (1214,3010) -->
        <ExitCode Value="-2067919934" Result="FailReboot"/>
        <!-- 0x84C10BC2 (1217,3010) -->
        <ExitCode Value="-2067723326" Result="FailReboot"/>
        <!-- 0x84BE0007 (1214,7) -->
        <ExitCode Value="-2067922937" Result="Fail" String="AdminRequired"/>
        <!-- 0x84C4001F (1220,31) -->
        <ExitCode Value="-2067529697" Result="Fail" String="AdminRequired"/>
        <!-- 0x84BE0001 (1214,1)-->
        <ExitCode Value="-2067922943" Result="Fail" String="InvalidPlatformOSServicePacks"/>
        <!-- 0x84C4000B (1220,11) -->
        <ExitCode Value="-2067529717" Result="Fail" String="AnotherInstanceRunning"/>
        <!-- 0x84BE01F8 (1214,504) -->
        <ExitCode Value="-2067922440" Result="Fail" String="BetaComponentsFailure"/>
        <!-- 0x84BE01FA (1214,506) -->
        <ExitCode Value="-2067922438" Result="Fail" String="BetaComponentsFailure"/>
        <!-- 0x84BE0202 (1214,514) -->
        <ExitCode Value="-2067922430" Result="Fail" String="InvalidPlatformArchitecture"/>
        <!-- 0x84BE0203 (1214,515) -->
        <ExitCode Value="-2067922429" Result="Fail" String="InvalidPlatformArchitecture"/>
        <ExitCode Value="216" Result="Fail" String="InvalidPlatformArchitecture"/>
        <DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />
      </ExitCodes>
    </Command>

  </Commands>

  <Strings>
    <String Name="DisplayName">SQL Server 2008 R2 Express</String>
    <String Name="Culture">en</String>
    <String Name="SqlExpr32Exe">http://download.microsoft.com/download/5/1/a/51a153f6-6b08-4f94-a7b2-ba1ad482bc75/SQLEXPR32_x86_ENU.exe</String>
    <String Name="SqlExpr64Exe">http://download.microsoft.com/download/5/1/a/51a153f6-6b08-4f94-a7b2-ba1ad482bc75/SQLEXPR_x64_ENU.exe</String>
    <String Name="AdminRequired">You do not have the permissions required to install SQL Server 2008 R2 Express. Please contact your administrator.</String>
    <String Name="GeneralFailure">An error occurred attempting to install SQL Server 2008 R2 Express.</String>
    <String Name="InvalidPlatformXP">Windows XP Service Pack 2 or later is required to install SQL Server 2008 R2 Express.</String>
    <String Name="InvalidPlatform2K3">Windows 2003 Service Pack 2 or later is required to install SQL Server 2008 R2 Express.</String>
    <String Name="MissingMSXml">SQL Server 2008 R2 Express requires MSXML. Please ensure MSXML is installed properly.</String>
    <String Name="InsufficientHardware">The current system does not meet the minimum hardware requirements for SQL Server 2008 R2 Express. Contact your application vendor.</String>
    <String Name="InvalidPlatformOSServicePacks">The current operating system does not meet Service Pack level requirements for SQL Server 2008 R2 Express. Install the most recent Service Pack from the Microsoft download center at http://www.microsoft.com/downloads before continuing setup.</String>
    <String Name="InvalidPlatformIE">This version of SQL Server 2008 R2 Express requires Internet Explorer version 6.0 with SP1 or later. To proceed, install or upgrade to a required version of Internet Explorer and then run setup again.</String>
    <String Name="AnotherInstanceRunning">Another instance of setup is already running. The running instance must complete before this setup can proceed.</String>
    <String Name="BetaComponentsFailure">A beta version of the .NET Framework 2.0 or SQL Server was detected on the computer. Uninstall any previous beta versions of SQL Server 2008 R2 components, SQL Server Support Files, or .NET Framework 2.0 before continuing.</String>
    <String Name="InvalidPlatformArchitecture">This version of SQL Server 2008 R2 Express is not supported for the current processor architecture.</String>
    <String Name="InvalidUpgradeNotExpress">The instance of SQL Server 2005 named 'SQLEXPRESS' is a not an instance of SQL Server Express. It cannot be upgraded to SQL Server 2008 R2 Express.</String>
    <String Name="InvalidUpgradeNotExpressCore">The instance of SQL Server 2005 Express named 'SQLEXPRESS' contains components that are not included in SQL Server 2008 R2 Express. SQL Server 2008 R2 Express SP1 cannot upgrade this instance. Please use SQL Server 2008 R2 Express with Advanced Services instead.</String>
    <String Name="InvalidUpgradeLanguage">The instance of SQL Server 2005 Express named 'SQLEXPRESS' is a different language version than this SQL Server 2008 R2 Express. SQL Server 2008 R2 Express cannot upgrade this instance.</String>
    <String Name="InvalidUpgradeWoW">SQL Server 2008 R2 Express (x64) cannot upgrade the existing instance of SQL Server 2005 Express (x64 WoW) named 'SQLEXPRESS'. Uninstall this instance of SQL Server 2005 Express and retry installing SQL Server 2008 R2 Express (x64).</String>
  </Strings>
</Package>

 

Step 3. 以SQL Server 2008 R2 Express的安裝檔替換原來的安裝檔

請刪除在SqlExpress2008R2\en資料夾下的SQLExpr_x64_enu.exeSQLExpr32_x86_enu.exe兩個檔案

image

接著下載SQL Server Express 2008 R2( 下載頁面在此,請記得x86和x64兩個版本都要下載喔!! )的安裝檔回來取代原來的兩個檔案。

image

image

 

Step 4. 關閉並重啟Visual Studio 2010

關閉並且重新開啟Visual Studio 2010之後再看一次Prerequisites列表,喔耶!!! 出現 SQL Server 2008 R2 Express這個選項了!! 打完收工!!

image