安装基于平台的不同版本的程序集? [英] Installing different version of assembly based on platform?

查看:129
本文介绍了安装基于平台的不同版本的程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建在VS2008安装程序的C#应用​​程序使用SQLite,这需要组装的x86和x64环境的不同版本。什么是有自动安装程序安装一个基于环境的正确装配的最佳方法是什么?

解决方案

最后,我最后不得不破解这个有点

。安装项目现在包括同时与x86和x64的SQLite版本的zip文件。我的项目安装程序类挂钩覆盖OnBeforeInstall方法,然后解压压缩文件到临时文件夹,检查环境,并拷贝正确版本的应用程序安装文件夹。

在code是沿着这些线路的东西,虽然日志和错误处理已经从这个例子中删除,以保持code有关。

 保护覆盖无效OnBeforeInstall(IDictionary的savedState)
{
    base.OnBeforeInstall(savedState);
    UnzipSQLite();
}

私人无效UnzipSQLite()
{
    //安装目录
    字符串TARGETDIR = Context.Parameters [TARGETDIR];

    // SQLite.zip由安装程序保存在临时文件夹
    //这是通过在Visual Studio中的GUI安装
    字符串的压缩文件= Path.Combine(TempFolder,SQLite.zip);

    //文件夹将被解压缩到
    字符串TEMPDIR = Path.Combine(TempFolder,Guid.NewGuid()的ToString());

    //将其解压缩。需要SharpZipLib
    FastZip FZ =新FastZip();
    fz.ExtractZip(zip文件,TEMPDIR,FastZip.Overwrite.Always,空,的String.Empty,的String.Empty,真正的);

    //检查操作系统是x86或x64
    // http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/24792cdc-2d8e-454b-9c68-31a19892ca53
    串子目录=(OSChecker.Is64BitOperatingSystem)? 64:86;

    //源和目标路径
    的字符串src = Path.Combine(TEMPDIR,子目录+\\ System.Data.SQLite.DLL);
    字符串DEST = Path.Combine(TARGETDIR,System.Data.SQLite.DLL);

    //将SQLite的DLL
    File.Move(SRC,DEST);

    // 全做完了。删除我们的temp文件夹。
    Directory.Delete(TEMPDIR,真正的);
}
 

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 the 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);
}

这篇关于安装基于平台的不同版本的程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆