在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互操作
发布评论