windows 单个 MSI 安装正确的 32 位或 64 位 c# 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3724956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Single MSI to install correct 32 or 64 bit c# application
提问by mchr
I have a C# application which is built for both x86 (32 bit) and x64 (64 bit) platforms. My build system currently outputs two MSI installers, one for each platform. In case it makes a difference, my C# application includes a windows taskbar toolbar which means that the installed DLL must be loaded by the explorer.exe process.
我有一个为 x86(32 位)和 x64(64 位)平台构建的 C# 应用程序。我的构建系统目前输出两个 MSI 安装程序,每个平台一个。以防万一,我的 C# 应用程序包含一个 Windows 任务栏工具栏,这意味着已安装的 DLL 必须由 explorer.exe 进程加载。
Is it possible to produce a single MSI installer which will install the correct version of my application depending on whether the current OS is a 64 bit OS?
是否可以生成单个 MSI 安装程序,根据当前操作系统是否为 64 位操作系统来安装我的应用程序的正确版本?
This has currently been achieved by using http://dotnetinstaller.codeplex.com/to produce an EXE which performs the architecture check and then launches the correct MSI. However, I would prefer a purely MSI based approach.
目前已通过使用http://dotnetinstaller.codeplex.com/生成执行架构检查然后启动正确 MSI 的 EXE 来实现这一点。但是,我更喜欢纯粹基于 MSI 的方法。
采纳答案by Michael Urman
No, this is not possible. See Heath Stewart's Different Packages are Required for Different Processor Architecturespost. The only way to handle this with MSI is with a bootstrap along the lines of what you describe. If you just needed to put a file or key or two in a 64-bit location, it's possible (but not recommended) to do that in a custom action, but changing the target installation location and using built-in MSI file support won't work.
不,这是不可能的。请参阅 Heath Stewart 的不同处理器架构所需的不同软件包帖子。使用 MSI 处理此问题的唯一方法是按照您所描述的方式使用引导程序。如果您只需要将一个或两个文件或密钥放在 64 位位置,则可以(但不推荐)在自定义操作中执行此操作,但更改目标安装位置并使用内置 MSI 文件支持将不起作用工作。
回答by Yochai Timmer
You could work around the problem. Pack the 2 installers under third deployment project. Create a custom action that checks the running OS version, then make the installer call the right installer.
你可以解决这个问题。在第三个部署项目下打包 2 个安装程序。创建一个自定义操作来检查正在运行的操作系统版本,然后让安装程序调用正确的安装程序。
Something like this:
像这样的东西:
[RunInstaller(true)]
public partial class MyInstaller: Installer
{
String installerPath;
public MyInstaller()
{
InitializeComponent();
if (Is64Bit())//running as 64-bit
{
installerPath= @"installfolder\my64bitsetup.exe";
}
else
{
installerPath= @"installfolder\my32bitsetup.exe";
}
}
[SecurityPermission(SecurityAction.Demand)]
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
}
[SecurityPermission(SecurityAction.Demand)]
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
MyInstall();
}
[SecurityPermission(SecurityAction.Demand)]
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
[SecurityPermission(SecurityAction.Demand)]
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
base.Commit(savedState);
}
private void MyInstall()
{
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd.exe", "/c " + installerPath);
RunProcess(procStartInfo);
}
private void RunProcess(ProcessStartInfo procStartInfo)
{
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();
proc.WaitForExit();
}
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo);
private bool Is64Bit()
{
return (IntPtr.Size == 8 || (IntPtr.Size == 4 && Is32BitProcessOn64BitProcessor()));
}
private bool Is32BitProcessOn64BitProcessor()
{
bool retVal;
IsWow64Process(Process.GetCurrentProcess().Handle, out retVal);
return retVal;
}
Ok, that was long...
好吧,那是长...
Anyway, in the Commit you can be sure that the installers are already unpacked, just make sure you have the right path. (You can change the cmd command from /c to /k for testings, that will keep the command prompt window alive for you to see the messages)
无论如何,在 Commit 中,您可以确保安装程序已经解压缩,只需确保您的路径正确即可。(您可以将 cmd 命令从 /c 更改为 /k 以进行测试,这将使命令提示符窗口保持活动状态,以便您查看消息)
You can read some more about custom actions, the installation path can be passed by arguments.
您可以阅读有关自定义操作的更多信息,安装路径可以通过参数传递。