System.Data.SQLite DLL 版本切換 32/64 Bit

專案是在 .NET 底下執行,當然最好還是編譯成 Any CPU,這時指定編譯為 32 Bit 的解法選項就不夠完美。在找解決方案的時候看了 Stackoverflow 的這一篇:

http://stackoverflow.com/questions/7264383/options-for-using-system-data-sqlite-in-a-32bit-and-64bit-c-sharp-world

參考了眾多解決方案都不太符合,後來想到的解法是使用 NSIS 做安裝檔案,預設複製 32 Bit 版本,安裝時當判斷作業系統是 64 Bit 時將 64 Bit 版本複製到應用程式執行路徑,反之則不複製,保持使用 32 Bit 版本。

 

Section "Main Program" MAINSEC

SetOutPath "$INSTDIR"
SetOverwrite ifnewer

; Those files are included with the installer
File /nonfatal /a /r ..\bin\Debug\en\
File /nonfatal /a /r ..\bin\Debug\zh-Hans\
File /nonfatal /a /r ..\bin\Debug\zh-Hant\
File ..\bin\Debug\App.exe
File ..\bin\Debug\App.exe.config
File ..\bin\Debug\System.Data.SQLite.dll
File ..\bin\Debug\System.Data.SQLite.xml
File /nonfatal /a /r ..\bin\Debug\Tools\

;Store installation folder
WriteRegStr HKCU "Software\FETAG\MyApp" "" $INSTDIR

;Create shortcuts
CreateDirectory "$SMPROGRAMS\MyApp"
CreateShortCut "$SMPROGRAMS\MyApp\App.lnk" "$INSTDIR\App.exe"
CreateShortCut "$SMPROGRAMS\MyApp\UnInstall.lnk" "$INSTDIR\Uninstall.exe"

CreateShortCut "$DESKTOP\MyApp.lnk" "$INSTDIR\App.exe"

;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"

; x32 or x64 DLL
!include "x64.nsh"
${If} ${RunningX64}
; MessageBox MB_OK|MB_ICONSTOP '64 Bit'
${Else}
; MessageBox MB_OK|MB_ICONSTOP '32 Bit'
CopyFiles "$INSTDIR\Tools\System.Data.SQLite.dll" "$INSTDIR\System.Data.SQLite.dll"
${EndIf}
SectionEnd

另外一個 AssemblyResolver 的方法看起來還是太麻煩了。

 

Got Something To Say:

Your email address will not be published. Required fields are marked *

*

Copyright © 2017. Powered by WordPress & Romangie Theme.