Creating the Primary Interops Microsoft left out
As many developers have discovered, if you’ve written a VB6 dll that you decided to use from .NET, and you decided to create primary interops for your DLL(s), then you will encounter a snag. In order to create a primary interop, all of the exposed types also need primary interops. The usual suspects are:
- ADODB (exposed recordsets)
- VBA (exposed collections)
- VBRUN (? not sure)
- Scripting (Dictionaries, File System Objects)
Microsoft supplies ADODB with VS.NET, so there is no problem there. But the others you will have to create yourself. Here is the Nant script I use to do that:
<target name="PrepareThirdPartyInterops">
<regasm unregister="false" codebase="false" assembly="${build.dir}\ADODB.dll" />
<regasm unregister="false" codebase="false" assembly="${build.dir}\Microsoft.stdformat.dll" />
<regasm unregister="false" codebase="false" assembly="${build.dir}\msdatasrc.dll" />
<gac action="uninstall" failonerror="false">
<assemblies>
<include name="${build.dir}\interop.scripting.dll" />
<include name="${build.dir}\interop.vba.dll" />
<include name="${build.dir}\interop.stdformat.dll" />
<include name="${build.dir}\interop.vbrun.dll" />
</assemblies>
</gac>
<tlbimp typelib="${system32}\scrrun.dll" output="${build.dir}\interop.scripting.dll" asmversion="5.6.0.8820"
namespace="scripting" keyfile="${build.dir}\mykeyfile.snk" primary="true" />
<tlbimp typelib="${system32}\msvbvm60.dll" output="${build.dir}\interop.vba.dll" asmversion="6.0.97.82"
namespace="vba" keyfile="${build.dir}\mykeyfile.snk" primary="true" />
<tlbimp typelib="${system32}\MSVBVM60.DLL\3" output="${build.dir}\interop.vbrun.dll" asmversion="6.0.0.0"
namespace="vbrun" keyfile="${build.dir}\mykeyfile.snk" primary="true">
<references>
<include name="${build.dir}\interop.vba.dll" />
<include name="${build.dir}\Microsoft.stdformat.dll" />
<include name="${build.dir}\msdatasrc.dll" />
</references>
</tlbimp>
<gac action="install">
<assemblies>
<include name="${build.dir}\interop.scripting.dll" />
<include name="${build.dir}\interop.vba.dll" />
<include name="${build.dir}\interop.vbrun.dll" />
</assemblies>
</gac>
</target>
One last note. Microsoft.stdformat.dll and msdatasrc.dll are necessary for vbrun. They are available from Microsoft as part of the Office 2003 Primary Interop download. ADODB is also in there, in case you don’t have it.