VSTO 工具:Office 2010 到 2013 升级 [英] VSTO Tools: Office 2010 to 2013 upgrade

查看:65
本文介绍了VSTO 工具:Office 2010 到 2013 升级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Excel 开发 VSTO 工具项目.我现在正在升级我的机器.我的旧"笔记本电脑运行的是带有 Office 2010 和 Visual Studio 2012 的 Windows 7 x64.我的新机器带有带有 Office 2013 和 Visual Studio 2012 的 Windows 8 x64.

I'm working on a VSTO tools project for Excel. I'm now in the process of upgrading my machine. My "old" laptop was running Windows 7 x64 with Office 2010 and Visual Studio 2012. My new machine has Windows 8 x64 with Office 2013 and Visual Studio 2012.

在 VS2012 上打开我的解决方案时,在新机器上,它给我一个错误加载项目:

When opening my solution on VS2012, in the new machine, it gives me an error loading the project:

无法创建项目,因为与此关联的应用程序此计算机上未安装项目类型.您必须安装与此项目关联的 Microsoft Office 应用程序类型.

Cannot create the project because the application associated with this project type is not installed on this computer. You must install the Microsoft Office application that is associated with this project type.

我认为这是由于 Office 升级.除非真的有必要,否则我不想回到 Office 2010.

I reckon this is due to the Office Upgrade. I don't want to come back to Office 2010 unless it's really necessary.

你有什么建议吗?

最好的问候,jpsfs

Best regards, jpsfs

推荐答案

我的解决方案

好的,所以在我的头撞墙很多次之后——发现 msbuild 属性、条件和项目 inlcudes 不适用于/在 ProjectExtensions 部分中,我想出了一个额外的 hack 使我的 .csproj 在 Visual Studio 2013 [更新 3] 中工作,无论开发人员安装了 Office 2010 还是 Office 2013(在下面的第二个要点中有详细说明——VS 2010 中的相同行为不需要,VS 2012 的 YMMV).

Okay, so after a lot of banging my head against the wall -- finding out the msbuild properties, conditions, and project inlcudes don't work for/in the ProjectExtensions section, I figured out an additional hack that makes my .csproj work in Visual Studio 2013 [Update 3] whether the developer has Office 2010 or Office 2013 installed (it's detailed in the second bullet point below -- which is not required for the same behavior in VS 2010, YMMV for VS 2012).

要使您的项目以这种方式工作,您需要做以下三件事:

To make your project work this way you need to do these three things:

  • 手动编辑您的 .csproj 文件并找到所有 Office 互操作程序集参考——确保版本设置为版本14.0.0.0"(而不是15.0.0.0")并且SpecificVersion" 子元素存在并设置为 "False".

  • Hand edit your .csproj file and find all the office interop assembly references -- make sure the version is set to version "14.0.0.0" (as opposed to "15.0.0.0") and that the "SpecificVersion" child element is present and set to "False".

在 Project\ProjectExtensions\VisualStudio\FlavorProperties\ProjectProperties 元素下,找到OfficeVersion"属性/值对并将其删除(因此读取的属性为 OfficeVersion="14.0" --删除那个).-- 保留所有其他 14.0s 不变,如果有任何更改为 15.0,则将其降级回 14.0(再次,如果它是参考,请将 SpecificVersion 设置为 false).-- 不必担心更改任何 GUID,只需保持原样即可!

Under the Project\ProjectExtensions\VisualStudio\FlavorProperties\ProjectProperties element find the "OfficeVersion" attribute/value pair and remove it (so the attribute that reads OfficeVersion="14.0" -- delete that). -- Leave all other 14.0s intact, if anything got changed to 15.0, downgrade it back to 14.0 (and again, if it's a reference, set SpecificVersion to false). -- Do not worry about changing any GUIDs, just leave them as they are!

此时,该解决方案将在运行 Visual Studio 2013 的机器上打开并编译,无论它们是安装 Office 2010 还是 Office 2013. -- 但它不会启动解决方案运行 Office 2013 的机器.要解决这个问题:

At this point, the solution will open and compile on machines that are running Visual Studio 2013 whether they have Office 2010 or Office 2013. -- But it will not start the solution on machines running Office 2013. To fix that:

  • 打开 regedit 并导航到 HKLM\Software\Microsoft\Office\
  • 将整个 15.0 分支导出到 .reg 文件.
  • 在记事本中打开该文件并将所有出现的15.0"注册表路径更改为14.0".
  • 重新保存文件(确保将其保存为 unicode).
  • 导入文件 &重新启动 Visual Studio.-- 这将允许您开始使用 Office 2013 进行调试.

要记住的另一件事——特别是如果您使用 EmbedInteropTypes,请确保在您进行发布/发布构建时,您是从安装了 Office 2010(而不是 2013)的机器上进行的,以便发布的程序集是针对 Office 2010 特定库构建的.-- 这将保持您在两个版本之间具有向后和向前兼容性.

One other thing to keep in mind -- especially if you use EmbedInteropTypes, make sure that when you do your release / publish build that you do it from a machine with Office 2010 (and not 2013) installed, so that the published assembly is built against the Office 2010 specific libraries. -- This will maintain that you have backward and forward compatibility between the two versions.

同样,这对我来说适用于 Word 插件——对于 Excel 插件 YMMV.

Again, this worked for me for a Word Add-in -- For an Excel Add-in YMMV.

原始答案"(可能包含对其他人有用的详细信息)

我在上面的评论中提到我遇到了相反的问题——如果用户安装了 Office 2013,VS 2013 Update 3 会强制升级我的项目.

I mentioned in comments above that I'm having the opposite problem -- VS 2013 Update 3 is forcibly upgrading my projects if the user has Office 2013 installed.

您可以尝试安装 VS 2013 Update 3(即使是暂时的,比如在虚拟机中)和最新的 VSTO 2012/2013 版本,并打开项目,它应该也会强制升级您的项目.我知道您使用的是 Excel,而我使用的是 Word,但它正在升级的部分:

You can try installing VS 2013 Update 3 (even temporarily, say in a VM) and the latest VSTO 2012 / 2013 version, and opening the project, it should forcibly upgrade yours as well. I know you're using Excel, and I'm using Word, but the section it's upgrading:

旧的 .csproj XML:

<Project ...>
  ...
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{BAA0C2D2-18E2-41B9-852F-F413020CAA33}">
        <ProjectProperties HostName="Word" HostPackage="{20A848B8-E01F-4801-962E-25DB0FF57389}" OfficeVersion="14.0" VstxVersion="4.0" ApplicationType="Word" Language="cs" TemplatesPath="VSTOTemplates" DebugInfoExeName="#Software\Microsoft\Office\14.0\Word\InstallRoot\Path#WINWORD.EXE" DebugInfoCommandLine="/w" AddItemTemplatesGuid="{51063C3A-E220-4D12-8922-BDA915ACD783}" />
        <Host Name="Word"... />
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>
  ...
</Project>

新的 .csproj XML:

<Project ...>
  ...
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{BAA0C2D2-18E2-41B9-852F-F413020CAA33}">
        <ProjectProperties HostName="Word" HostPackage="{29A7B9D7-A7F1-4328-8EF0-6B2D1A56B2C1}" OfficeVersion="15.0" VstxVersion="4.0" ApplicationType="Word" Language="cs" TemplatesPath="VSTOTemplates" DebugInfoExeName="#Software\Microsoft\Office\15.0\Word\InstallRoot\Path#WINWORD.EXE" DebugInfoCommandLine="/w" AddItemTemplatesGuid="{51063C3A-E220-4D12-8922-BDA915ACD783}" />
        <Host Name="Word"... />
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>
  ...
</Project>

在我看来,发生变化的两件事是:

Looks to me like the two things that changed are:

  • 从 14.0 到 15.0 的注册表路径(在 VS 2010 中很容易解决 - 您刚刚创建了一个匹配的 14.0 注册表路径,指向您安装 Word 2013 的位置,并且运行良好).

  • The registry path from 14.0 to 15.0 (which in VS 2010 was easy to work around -- you just created a matching 14.0 registry path that pointed to where you installed Word 2013 and it worked fine).

主机包的 CLS ID.我不知道它们是什么 Excel,但您可能可以查找它们.-- 我宁愿不更改已签入项目的 CLS ID,以便开发人员开发 &可以继续针对 Word 2010 测试项目,以及针对 Word 2013 进行开发和测试的项目.

The host package's CLS ID. I don't know what they are for Excel, but you can probably look them up. -- I prefer not to change the CLS ID of the checked in project, such that developers developing & testing the project against Word 2010 can continue to do so, as well as those developing and testing against Word 2013.

另外要注意的是,似乎有两个引用也从 14.0 更新到了 15.0——这是一个主要的禁忌——因为我们只想针对/嵌入 2010 年互操作类型(这些在 2013 年工作正常,但我们不想意外地访问一些 2013 年唯一的财产,然后让它在 2010 年不起作用......)

Of additional note it looks like two references got updated from 14.0 to 15.0 as well -- this is a major no-no -- since we want to only build against/embed the 2010 Interop Types (these work fine in 2013, but we don't want to accidentally access some 2013 only property and then have it not work in 2010...)

更新的两个引用是Microsoft.Office.Interop.Word"和Office".

The two references that got updated are "Microsoft.Office.Interop.Word" and "Office".

看起来我可以将这两个引用设置为 SpecificVersion: False,然后手动编辑 XML 文件以将它们退回到14.0.0.0"(版本似乎从常规菜单中变灰).

Looks like I can set those two references to SpecificVersion: False, and then hand edit the XML file to step them back down to "14.0.0.0" (version seems to be grayed out from the regular menu).

这篇关于VSTO 工具:Office 2010 到 2013 升级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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