我终于有一个似乎可行的答案。
将 32 位和 64 位版本(托管和非托管)编译到单独的文件夹中。然后让 .NET 应用在运行时选择从哪个目录加载程序集。
使用 ResolveEvent 的问题在于,只有在找不到程序集时才会调用它,因此很容易意外地以 32 位版本结束。而是使用第二个 AppDomain 对象,我们可以在其中更改 ApplicationBase 属性以指向正确的文件夹。所以你最终得到如下代码:
static void Main(String[] argv)
  {
     // Create a new AppDomain, but with the base directory set to either the 32-bit or 64-bit
     // sub-directories.
     AppDomainSetup objADS = new AppDomainSetup();
     System.String assemblyDir = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
     switch (System.IntPtr.Size)
     {
        case (4): assemblyDir += "\\win32\\";
           break;
        case (8): assemblyDir += "\\x64\\";
           break;
     }
     objADS.ApplicationBase = assemblyDir;
     // We set the PrivateBinPath to the application directory, so that we can still
     // load the platform neutral assemblies from the app directory.
     objADS.PrivateBinPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
     AppDomain objAD = AppDomain.CreateDomain("", null, objADS);
     if (argv.Length > 0)
        objAD.ExecuteAssembly(argv[0]);
     else
        objAD.ExecuteAssembly("MyApplication.exe");
     AppDomain.Unload(objAD);
  }
你最终有 2 个 exes - 你的普通应用程序和第二个切换应用程序,它选择要加载的位。注意 - 我自己不能相信这个细节。鉴于我最初的指示,我的一位同事对此提出了质疑。如果他注册 StackOverflow,我会将答案分配给他