Visual Studio 2010 TlbImp在2.0项目中生成.net 4.0互操作

编程入门 行业动态 更新时间:2024-10-19 11:51:11
本文介绍了Visual Studio 2010 TlbImp在2.0项目中生成 4.0互操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在C#项目中,我们通过添加引用"设置将指向COM对象的引用添加到COM对象,这导致IDE自动生成互操作程序集.因此,这很好,而且很好,但是我们基于 3.5 SP1 aka CLR 2.0进行构建,并且生成的互操作使用4.0 CLR使它们不兼容.有办法防止这种情况吗?

In a C# project we add a reference to a COM object via the Add References setup pointing to a COM object which results in the IDE auto-generating the interop assembly. So this is fine and good, but we are building based on 3.5 SP1 aka CLR 2.0, and the generated interops are using the 4.0 CLR making them incompatible. Is there a way to prevent this?

我假设另一个选项是配置我们的构建脚本,以尝试将tlbimp.exe与/references参数一起使用?指向mscorlib v2.0?

I assume the other option is configure our build script to try using tlbimp.exe with the /references parameter? to point to mscorlib v2.0?

无论如何,我希望某处有一个标志可以允许这样做.

Anyhow, I'm hoping there's a flag somewhere to allow this.

推荐答案

我恰好遇到了这个问题.我发现的解决方案是使用.Net Framework SDK(或Windows Platform SDK?)中的tlbimp 3.5版,该文件位于使用CLR 2的%ProgramFiles%\ Microsoft SDKs \ Windows \ v6.0A \ bin中.

I encountered exactly this issue. The solution I found was to use version 3.5 of tlbimp from the .Net Framework SDK (or Windows Platform SDK?) located in %ProgramFiles%\Microsoft SDKs\Windows\v6.0A\bin that used CLR 2.

我还发现我需要此信息来从导入的exe文件中获取正确的类型库,因为VS仅使用第一个类型库:

I also found I needed this info to get the correct type library from the exe file i was importing, as VS would use only the first type library:

从包含多个类型库的模块中导入类型库时,可以选择将资源ID附加到类型库文件中."

"A resource ID can optionally be appended to a type library file when importing a type library from a module containing multiple type libraries."

tlbimp MyModule.dll \ 1

tlbimp MyModule.dll\1

来自 msdn.microsoft/en-us/library/tt0cf3sx%28VS.80%29.aspx

更多推荐

Visual Studio 2010 TlbImp在2.0项目中生成.net 4.0互操作

本文发布于:2023-11-07 10:57:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566266.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作   项目   Visual   Studio   TlbImp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!