Excel 对象库 - 使用 16.0 编译的应用程序并尝试 运行 在不同的计算机上使用 12.0

Excel Object Library - app compiled using 16.0 and try to run using 12.0 on different computer

  1. 我安装了 Office 2016 的计算机 A - 包括用于开发应用程序的 Office COM 库 - Excel 对象库用于创建应用程序(Microsoft.Office.Interop.Excel ver 15.0.0.0包含在 GAC 中)- 很棒,应用程序运行良好。

  2. 我的计算机 B 安装了 Office 2007 - 它的 GAC 中包含 Excel COM 库 - 版本 12.0.0.0 和版本 14.0.0.0。我想 运行 我的应用程序(来自计算机 A)在此计算机上。

  3. 我将 App.config 文件添加到我的 WPF 应用程序中,如下所示:

      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="Microsoft.Office.Interop.Excel"
                              publicKeyToken="71e9bce111e9429c"
                              culture="neutral" />
            <bindingRedirect oldVersion="15.0.0.0"
                             newVersion="12.0.0.0"/>
         </dependentAssembly>
    
         <dependentAssembly>
            <assemblyIdentity name="office"
                              publicKeyToken="71e9bce111e9429c"
                              culture="neutral" />
            <bindingRedirect oldVersion="15.0.0.0"
                             newVersion="12.0.0.0"/>
         </dependentAssembly>  
      </assemblyBinding> 
    

所以我试图在安装了旧版本 Office 的计算机上使用这两个库的旧版本。我读到可以将旧版本设置为 newVersion="" 的值。我在我的部署中包含 myApp.exe.config,但应用程序仍然尖叫,似乎 Excel 未安装。

  1. 我最后的办法是使用安装了 Office 2007 的虚拟机,下载 Visual Studio 并重新编译项目更新对旧版本 Excel 对象库的引用 - 但也许还有另一种方法让我的应用程序在计算机 B 上与 Excel 对象库版本 12.0.0.0 一起工作。在我决定使用这个 'virtual tank'.
  2. 之前,如果有任何想法,我将不胜感激
  1. 我只是从 App.config 中的 assemblyIdentity 和 bindingRedirect 中删除了 \n,它现在可以工作了:

     <dependentAssembly>
        <assemblyIdentity name="Microsoft.Office.Interop.Excel" publicKeyToken="71e9bce111e9429c" culture="neutral" />
        <bindingRedirect oldVersion="15.0.0.0" newVersion="12.0.0.0"/>
     </dependentAssembly>
    
     <dependentAssembly>
        <assemblyIdentity name="office" publicKeyToken="71e9bce111e9429c" culture="neutral" />
        <bindingRedirect oldVersion="15.0.0.0" newVersion="12.0.0.0"/>
     </dependentAssembly>