如何使用两种不同的微软互操作程序集在一个项目? [英] How to use two different Microsoft Interop assemblies in one project?

查看:184
本文介绍了如何使用两种不同的微软互操作程序集在一个项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用两个不同的Microsoft.Office.Interop组件(版本11和12),这取决于安装在客户机上的Office版本。

我已经能够在这两个asseblies添加到我的项目(​​我用他们loccaly - 他们都在我的bin文件夹,有两种不同势子文件​​夹),我用这个组件别名能够使用他们两个人在我的项目(​​分别别名是Excel11和Excel12)。

但unfourtunately,当我试图构建解决方案我得到警告:

  

没有办法解决冲突   的Microsoft.Office.Interop.Excel,   版本= 12.0.0.0,文化=中立,   公钥= 71e9bce111e9429c和   的Microsoft.Office.Interop.Excel,   版本= 11.0.0.0,文化=中立,   公钥= 71e9bce111e9429c。   选择   的Microsoft.Office.Interop.Excel,   版本= 12.0.0.0,文化=中立,   公钥= 71e9bce111e9429c   随意。

解决方案

是啊,那是严重的,但可以理解的。我强烈建议寻找到的Open XML SDK的COM-少代。但我知道时间crunchs等方面的要求,所以如果你不能......这里就是我会做的。

要确保是在同一页上,这里就是我想的别名 HTTP:// WWW。 dotnetperls.com/extern~~V 如果不工作你一些奇怪的原因,也可以使用下面的另一种方法。

有关清洁,你可以创建两个新的项目。为每个需要实现,它们命名为特定像Excel11,Excel12什么版本的版本。

然后建立包装类,你希望能够从每个访问的功能,你可以得到看中丹西和建立一个抽象类,在一个单独的共同的项目,你的包装类扩展,这样你就可以一般地从你的主引用它们code。通过对均匀性的抽象类的名称。你只需要添加在您的主项目引用的新项目,其中包装您要根据然而您检查的版本,注册表项或其他选择。希望它能帮助。

I want to use two different Microsoft.Office.Interop assemblies (version 11 and 12) depending on the Office version installed on customer's machine.

I've been able to add these two asseblies to my project ( I am using them loccaly - they are in my bin folder, in two diffrent subfolders) , I used aliases on this assemblies to be able to use both of them in my project (respectively, aliases are Excel11 and Excel12).

But unfourtunately, when I am trying to build the solution I am getting warning:

No way to resolve conflict between "Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" and "Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c". Choosing "Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" arbitrarily.

解决方案

yeah that's gross, but understandable. I strongly recommend looking into the Open XML SDK for COM-less generation. but i understand time crunchs and other requirements so if you can't...here's what i would do.

to make sure were on the same page, here's what i'm thinking of for aliasing http://www.dotnetperls.com/extern if for some odd reason that is not working for you, there is another approach you could use below.

For cleanliness you could create a couple new projects. one for each version you need to implement, name them something version specific like Excel11, Excel12.

Then build wrapper classes for the functions you want to be able to access from each, you could get fancy dancy and build an abstract class in a separate Common Project that your wrapper classes extend, so you can reference them generically from your main code by the Abstract class name for uniformity. you just need to add references to the new projects in your main project, and select which wrapper you want based on however you are checking version, registry keys or otherwise. Hope it Helps.

这篇关于如何使用两种不同的微软互操作程序集在一个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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