Excel COM 互操作 - tlbimp 与主要 WrapperTool
我正在尝试将 ActiveX Microsoft Excel 11.0 对象库添加到我的 .NET 项目中。它在我的计算机上运行良好,但是当我签入我的代码时,它在我同事的计算机上不起作用。把它修在他的身上,却把我的弄坏了。添加后,我们的机器之间的命名空间是不同的。
事实证明,不同之处在于,当我添加引用时,它使用 tlbimp 作为 WrapperTool,但对他来说,它使其成为主要引用。
我怎样才能让它以同样的方式为我们双方服务?他的机器不喜欢 tlbimp
导入互操作,而我的机器不喜欢 primary
互操作。
I'm trying to add the ActiveX Microsoft Excel 11.0 Object library to my .NET project. It works fine on my computer, but when I check in my code, it doesn't work on my coworker's. Fixed it on his and it broke mine. When added, the namespaces are different between our machines.
It turns out the difference is that when I add the reference it uses tlbimp
as the WrapperTool, but for him it makes it a primary
reference.
How do I make it work for both of us the same way? His machine doesn't like a tlbimp
imported interop, and mine doesn't like a primary
interop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们遇到了类似的问题,并且选项“tlbimp”适用于所有计算机。
我(不完美)的理解是:.NET 使用包装器程序集来访问 COM 组件。如果指定“primary”,则使用现有的预先生成的“主互操作程序集”。根据 http://msdn.microsoft.com/en-us/library/hfac4fky .aspx,“主互操作程序集由与其描述的类型库相同的发布者提供”。如果使用“primary”对您不起作用,则说明您的计算机上不存在该程序集。
默认值为“tlbimp”并且(根据我收集的信息)应该正常工作。如果它在您同事的计算机上不起作用,错误消息将会有所帮助。 VS2003 报告错误(搜索知识库文章“安装 Windows XP Service Pack 2 后在 Visual Studio .NET 中添加对 COM 对象的引用时收到错误消息”),但我不知道这是否适用到当前版本的 VS。
如果您无法完成这项工作,我建议您可以阅读有关“主互操作程序集”的更多信息,并尝试找到 Excel 的主互操作程序集位于同事计算机上的位置,然后将其复制到所有开发人员的计算机上。
希望这有帮助。
we had a similar problem, and the option "tlbimp" worked on all computers.
My (imperfect) understanding is: .NET uses wrapper assemblies to access COM components. If you specify "primary", you use an existing, pre-generated "primary interop assembly". According to http://msdn.microsoft.com/en-us/library/hfac4fky.aspx, "primary interop assemblies are provided by the same publisher as the type library they describe". If using "primary" does not work for you, this assembly does not exist on your computer.
The default is "tlbimp" and (from what I gathered) should normally work. If it does not work on your coworker's machine, the error message would be helpful. Errors were reported for VS2003 (search for the KB article "You receive an error message when you add a reference to a COM object in Visual Studio .NET after you install Windows XP Service Pack 2"), but I do not know if this applies to current versions of VS.
If you cannot make this work, I would suggest that you could read more about "Primary Interop Assemblies" and try to find where the primary interop assembly for Excel is located on your coworker's machine, then copy it to the machines of all developers.
Hope this helps.
我能够通过编辑注册表来解决此问题:
HKEY_CLASSES_ROOT\TypeLib{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}\2.4
这个存在,并且我添加了以下字符串值:
Name: PrimaryInteropAssemblyName
值:办公室,版本=12.0.0.0,文化=中性,PublicKeyToken=71e9bce111e9429c
I was able to solve this by editing the registy:
HKEY_CLASSES_ROOT\TypeLib{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}\2.4
This existed, and I added the following string value:
Name: PrimaryInteropAssemblyName
Value: office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c