I'm looking at migrating some legacy COM code written in VB6 to .NET, however this needs to generate a typelib that's fairly close to the original.
On the whole, everything works. However the typelib generated by regasm is giving a library name I can't seem to control.
The top of the generated IDL (from regasm backcompat.dll /tlb:backcompat.tlb
) looks like:
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: BackCompat.tlb
[
uuid(BF1F4E76-8F4A-420E-A58A-E041600AC02A),
version(1.0),
helpstring(".NET replacement for legacy VB objects")
]
library BackCompat
{
// TLib : // TLib : mscorlib.dll : {BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
importlib("mscorlib.tlb");
// TLib : Microsoft ActiveX Data Objects 6.1 Library : {B691E011-1797-432E-907A-4D8C69339129}
importlib("msado15.dll");
// TLib : : {4FB2D46F-EFC8-4643-BCD0-6E5BFA6A174C}
importlib("System.EnterpriseServices.tlb");
.
.
.
The specific declaration I'm trying to match is that against library
on line 10 which is coming out as BackCompat
(the name of the solution and DLL).
The namespace of the C# code is UtilityLib
, with the original classes in VB6 being UtilityLib.Database
, UtilityLib,Guid
, etc.; the prog IDs I can force with the ProgId attribute, but the library name itself seems elusive.
Unfortunatly, it seems that because the library is being declared as BackCompat
, then when trying to link against existing VB6 libraries that use early binding, builds fail as they're looking for UtilityLib.{whatever}
: so I have to make source code changes to reference BackCompat.{whatever}
; i.e., VB6 code that looks like this:
Dim dbConn As UtilityLib.Database
has to change to:
Dim dbConn as BackCompat.Database
Whilst changing all the VB6 in one hit would be marvellous, this isn't an option: legacy VB6 components will be swapped out over time and replaced with the .NET ones.
Renaming the file doesn't seem to solve this, so it must be getting the name from the assembly itself. Is there an attribute I can specify in AssemblyInfo.cs
to control this, or is it simply a case of fixing up the solution itself?
As mentioned by Hans in the comments to the question:
The library name is the same as the assembly name. Project > Properties > Build tab > "Assembly name" setting. Pretty hard to get this wrong, consider that your VB6 project might be referencing an old build of the type library.
Something I didn't consider (looked at everything else, didn't consider the project settings).