Office 2007 PIA

发布于 2024-11-28 06:03:30 字数 321 浏览 0 评论 0原文

我构建了一个应用程序,它使用 COM Interop 生成 Excel。它在我和我们用户的计算机上运行良好:Office 2007、Windows XP SP2。现在我将其迁移到另一台机器上,Office 2010,Windows 7 64位,并使用VS2008中的Visual Studio 2010,仍然运行良好。当我在用户的计算机上部署它时,我遇到了问题,他们使用相同的 Windows 7 64 位但 Office 2007。

因此,如果我在 Win7 64 位和 Office 2010 计算机上安装 Office 2007 PIA,请更改我的 Visual Studio 中的引用项目,能解决问题吗?

I built a application, it generates Excel with COM Interop. It works fine on mine and our user's machine: Office 2007, Windows XP SP2. Now I migrate it to another machine, Office 2010, Windows 7 64 bit, and use visual studio 2010 from VS2008, which still works fine. When I deploy it on my user's machine, I got the problem, they use the same Windows 7 64 bit but Office 2007.

So if I install Office 2007 PIA on my Win7 64 bit and Office 2010 machine, change the reference in my visual studio project, will that solve the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧夏天 2024-12-05 06:03:30

我知道这篇文章已经有一段时间了,但我想无论如何我都会投入两分钱,以防有人偶然发现它。

一般经验法则是在开发中使用与您计划支持的最旧 Office 版本链接的 PIA 版本。因此,如果您要支持 Office 2007 及更高版本,请在开发过程中使用 PIA 版本 12。

添加对 v12 PIA 的引用(通过 VSTO 在线下载 2007 PIA,或者如果您之前已经安装了 Office 2007,则从 GAC 下载)。现在您可能会想“好吧,我在 Visual Studio 中引用 v12,这现在应该可以在 Office 2007 上运行”。错误的。由于您引用的是 v12,但安装了 Office 2010,因此在程序集绑定期间,您的计算机会显示“好吧,请求 v12,但我们在 GAC 中安装了 v14,并且由于 PIA 向前兼容,我们将使用它”。即使您明确告诉它使用 v12,构建完成后您的机器将使用 v14。您可以通过 FUSLOG 确认这一点。 FUSLOG 是处理程序集绑定时使用的优​​秀工具。 注意:如果您认为应该在 FUSLOG 中看到任何内容,请清除 Internet Explorer 历史记录中的所有内容,然后重试。

要解决此问题,您需要停止所谓的“程序集绑定重定向'。这些 PIA 通常在 GAC 中拥有一个策略文件。策略文件的目的是在解析程序集时将旧的 PIA 版本重定向到新版本。要查看此内容,请执行以下操作:

  1. “Windows 键 + R” 打开运行菜单。
  2. 输入“C:\Windows\Assembly\GAC”并按 Enter 键。
    注意:我运行的是 32 位机器。您的 PIA 很可能安装在 GAC 中的不同位置,例如“C:\Windows\Assembly\GAC_MSIL”。

进入 GAC 后,向下滚动并查找您引用的 PIA 文件夹(例如 Microsoft.Office.Interop.Excel)。如果继续滚动,您应该会看到以“Policy”开头的文件夹,然后是数字,然后是 PIA 的名称(例如,Policy.12.0.Microsoft.Office.Interop.Excel)。这是执行绑定重定向的策略文件。打开该文件夹中的 XML 配置文件,您将看到类似以下内容的内容:

<?xml version="1.0" encoding="UTF-16"?><configuration>
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity publicKeyToken="71e9bce111e9429c" name="Microsoft.Office.Interop.Excel" culture="neutral"></assemblyIdentity>
            <bindingRedirect oldVersion="12.0.0.0" newVersion="14.0.0.0"></bindingRedirect>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

在上面的代码片段中,标签“bindingRedirect oldVersion ...”负责PIA程序集重定向。如果您注释掉该代码,如下所示:

<?xml version="1.0" encoding="UTF-16"?><configuration>
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity publicKeyToken="71e9bce111e9429c" name="Microsoft.Office.Interop.Excel" culture="neutral"></assemblyIdentity>
            <!--<bindingRedirect oldVersion="11.0.0.0" newVersion="12.0.0.0"></bindingRedirect>-->
        </dependentAssembly>
    </assemblyBinding>
</runtime>

那么这个重定向将被忽略。我对其进行评论而不是删除,只是因为该文件确实有很好的用途,但在为旧版本的 Office 进行开发时则不然。对您需要的每个 PIA 策略文件执行此操作,您的开发计算机将停止重定向。

希望这能回答您的问题!

I know this post was awhile back, but I figured I'd throw in my two cents anyway in case someone stumbles upon it.

A general rule of thumb is to use the PIA version in development that links up with the oldest version of Office you plan to support. So, if you're going to support Office 2007 and up, use version 12 of the PIAs during development.

Add a reference to v12 PIAs (either by downloading the 2007 PIAs online, via VSTO, or from the GAC if you already had Office 2007 instead previously). Now you might think "Ok, I'm referencing v12 in Visual Studio, this should now work on Office 2007". Wrong. Since you're referencing v12 but you have Office 2010 installed, during assembly binding your machine will say "Well, v12 is requested, but we have v14 installed in the GAC and since PIAs are forward compatible, we'll use that". Even though you explicitly tell it to use v12, after completion of a build your machine will be using v14. You can confirm this via FUSLOG. FUSLOG is an excellent tool to use when working with assembly binding. Note: If you're not seeing anything in FUSLOG and you think you should, clear everything in your Internet Explorer history and try again.

To fix this problem you need to stop what's called 'assembly binding redirection'. These PIAs usually have a policy file with them in the GAC. The purpose of the policy file is to redirect older PIA versions to newer versions when resolving the assembly. To see this, do the following:

  1. Press 'Windows key + R' to open the run menu.
  2. Type 'C:\Windows\Assembly\GAC' and press Enter.
    Note: I am running a 32bit machine. Your PIAs will most likely be installed in a different location in the GAC, such as 'C:\Windows\Assembly\GAC_MSIL'.

Once in the GAC, scroll down and look for the folders of PIAs you reference (e.g. Microsoft.Office.Interop.Excel). If you continue scrolling, you should see folders that start with 'Policy', then a number, then the name of the PIA (e.g. Policy.12.0.Microsoft.Office.Interop.Excel). This is the policy file that performs binding redirection. Open the XML configuration file within that folder and you will see something similar to the following:

<?xml version="1.0" encoding="UTF-16"?><configuration>
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity publicKeyToken="71e9bce111e9429c" name="Microsoft.Office.Interop.Excel" culture="neutral"></assemblyIdentity>
            <bindingRedirect oldVersion="12.0.0.0" newVersion="14.0.0.0"></bindingRedirect>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

In the above code snippet, the tag "bindingRedirect oldVersion ..." is responsible for the PIA assembly redirection. If you comment out that code like the following:

<?xml version="1.0" encoding="UTF-16"?><configuration>
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity publicKeyToken="71e9bce111e9429c" name="Microsoft.Office.Interop.Excel" culture="neutral"></assemblyIdentity>
            <!--<bindingRedirect oldVersion="11.0.0.0" newVersion="12.0.0.0"></bindingRedirect>-->
        </dependentAssembly>
    </assemblyBinding>
</runtime>

Then this redirection will be ignored. I comment it rather then deleting simply because the file does serve a good purpose, just not when developing for older versions of Office. Perform this on each PIA Policy file that you require, and your development machine will stop redirection.

Hopefully this answers your question!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文