Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010, TlbImp generates .net 4.0 interops in 2.0 projects

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 .net 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?

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.

like image 220
DJScrib Avatar asked Apr 17 '10 19:04

DJScrib


1 Answers

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.

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:

"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

from http://msdn.microsoft.com/en-us/library/tt0cf3sx%28VS.80%29.aspx

like image 116
Skym Avatar answered Oct 01 '22 05:10

Skym