Installing different version of assembly based on platform?
I'm creating a setup program in VS2008 for a C# application that uses SQLite, which requires different versions of the assembly for x86 and x64 environments. What is th开发者_高级运维e best way to have the setup program automatically install the correct assembly based on the environment?
Eventually, I ended up having to hack this a bit. The setup project now includes a zip file with both the x86 and x64 versions of SQLite. My project installer class hooks overrides the OnBeforeInstall method, and then unzips the zip file to a temp folder, checks the environment, and copies the correct version to the application installation folder.
The code is something along these lines, though logging and error handling has been removed from this example to keep the code relevant.
protected override void OnBeforeInstall(IDictionary savedState)
{
base.OnBeforeInstall(savedState);
UnzipSQLite();
}
private void UnzipSQLite()
{
// Installation directory
string targetDir = Context.Parameters["TargetDir"];
// SQLite.zip is saved in the temp folder by the installer
// This is setup via the GUI in Visual Studio
string zipFile = Path.Combine(TempFolder, "SQLite.zip");
// Folder where it will be unzipped to
string tempDir = Path.Combine(TempFolder, Guid.NewGuid().ToString());
// Unzip it. Requires SharpZipLib
FastZip fz = new FastZip();
fz.ExtractZip(zipFile, tempDir, FastZip.Overwrite.Always, null, string.Empty, string.Empty, true);
// Check if OS is x86 or x64
// http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/24792cdc-2d8e-454b-9c68-31a19892ca53
string subDir = (OSChecker.Is64BitOperatingSystem) ? "x64" : "x86";
// Source and destination paths
string src = Path.Combine(tempDir, subDir + "\\System.Data.SQLite.DLL");
string dest = Path.Combine(targetDir, "System.Data.SQLite.DLL");
// Move the SQLite DLL
File.Move(src, dest);
// All done. Delete our temp folder.
Directory.Delete(tempDir, true);
}
精彩评论