使用和不使用 VSTO 开发 Office 2007/2010 加载项的相对优点是什么?

发布于 2024-11-30 12:30:37 字数 863 浏览 2 评论 0原文

几年前,我为 Office 2003(Word、Excel 和 PowerPoint)进行了一些非常认真的 Office 插件开发。我使用 Visual Studio 2003 在 C# 中创建了一些共享 COM 加载项。当时,我查看了 VSTO,但由于我不完全记得的原因,我决定它不适合我的需要。

我的加载项现在需要升级,不再需要支持 Office 2003 - 尽管它们仍然需要支持 Office 2007,而不仅仅是 2010。

我知道事情已经发生了重大变化,并且 Visual Studio 2010 具有更好的功能支持Office开发。我想确定是否应该使用 VSTO 重新实现我的加载项,或者继续使用共享 COM 加载项路线。

如果有人知道每种方法的优缺点的很好的总结(除了营销炒作之外),我很想听听。

我第一次发现非常令人沮丧的事情(没有使用 VSTO,但无论如何都可能适用):

  • 需要显式管理 COM 引用(并调用 ReleaseComObject 随处可见)
  • 需要 COM 填充程序才能使安全模型发挥作用
  • Visual Studio 安装项目根本不起作用;我结束了 构建我自己的基于 MSI 的安装程序
  • 缺乏文档,尤其是上述所有方面的文档;我花了 数周的反复试验和随机搜索博客; MS 提供的 示例代码完全忽略了所有这些现实问题

还值得一提的是,最大限度地减少在我的加载项之前需要安装的东西的数量很重要。我认为让我放弃 VSTO 的原因之一是需要部署额外的东西(尽管因为我从未走这条路,所以我不知道这种担忧是否合理)。我真的希望能够在标准 Windows 7(或 Vista)版本上进行部署,而无需首先安装(例如).NET 4。

Several years ago, I did some pretty serious Office add-in development for Office 2003 (Word, Excel and PowerPoint). I created some shared COM add-ins in C# using Visual Studio 2003. At the time, I looked at VSTO, but decided for reasons that I can't fully remember that it was not suitable for my needs.

My add-ins are due for an upgrade now, and no longer need to support Office 2003 - though they do still need to support Office 2007, not just 2010.

I know that things have moved on significantly, and that Visual Studio 2010 has better support for Office development. I'd like to determine whether I should re-implement my add-ins using VSTO, or continue with the shared COM add-in route.

If anyone knows of a nice summary of the pros and cons of each approach (beyond the marketing hype), I'd love to hear it.

Things that I found very frustrating first time around (not using VSTO, but may apply anyway):

  • the need to manage COM references explicitly (and call
    ReleaseComObject everywhere)
  • the need for a COM shim to get the security model to work
  • visual studio installation projects just plain didn't work; I ended
    up building my own MSI-based installer
  • lack of documentation, particularly on all of the above; I spent
    weeks of trial-and-error and searching random blogs; the MS-supplied
    example code completely ignored all of these real-world issues

It's also worth mentioning that minimising the amount of stuff that needs to be installed prior to my add-ins is important. I think that one of the things that put me off VSTO was the need to deploy additional stuff (though since I never went down that route I don't know if that concern was justified). And I'd really like to be able to deploy on a standard Windows 7 (or Vista) build without the need to first install (say) .NET 4.

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

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

发布评论

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

评论(1

美胚控场 2024-12-07 12:30:37

部分答案,但太长,无法容纳评论:

我可以评论的部分:

  • VSTO 插件的设置项目现在确实可以工作,并且有一个非常好的演练可以介绍如何正确创建它们。
  • 恕我直言,Office 对象模型的一般文档很差,这对于 com 和 c# 开发来说同样令人烦恼。因为如果您使用 .net Framework v4,许多对象现在都会作为动态返回,您会失去智能感知,这没有帮助。解决方法是尽可能明确地转换为已知类型。
  • 为了运行它显然需要安装相关的框架(v4 在这方面比早期版本要好得多,因为在 Office 组和 NoPIA 设置的压力下添加了动态、可选参数)此外,它还需要安装 VSTO 运行时。
  • 所有这些依赖项都可以合并到安装程序中,但它们是必需的

您没有指定用于创建这些 com 插件的内容(我猜测是 c++ 或 vb6),我无法判断它们有多大以及它们有多少大修需要,所以如果现在是做出改变的时候,实际上不可能提供建议。迁移到 c# 肯定会变得更加干净和更好的领域之一是与功能区相关的任何内容。但我再次无法估计这对你来说有多重要。

Partial answer but too long to fit in a comment:

Parts I can comment on:

  • Setup projects for VSTO addins now do actually work and there is a very good walkthrough available on how to create them properly.
  • Documentation in general of the office object model is poor imho and that should be equally annoying for com and c# development. Because a lot of the objects are now returned as dynamics if you use .net framework v4 you loose intellisense which does not help. The workaround for that is to be explicit in casting to known types where possible.
  • In order to run it obviously needs the relevant framework installed (v4 is FAR better for this than earlier version because of dynamics, optional arguments that were added under pressure from the office group and the NoPIA setting) Besides that it also needs the VSTO runtime installed.
  • All of these dependencies could be incorporated into the installer but they are required

You haven't specified what you used to create those com addins (My guess is c++ or vb6) and I can't tell how large they are and how much overhaul they need so it's not really possible to give advice if now is the time to make the change. One of the areas where moving to c# will certainly be far cleaner and nicer is anything related to ribbons. But again I can't estimate how relevant that is for you.

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