Evan said:
The thing I'm running into presently is that I'd really like to be
able to specify the namespace of Office.dll (since by default it
wants to create an Office namespace, and I'd really rather have
Interop.Office or something along those lines). However, TLBIMP only
seems to let me do that with the immediate library I'm generating (in
this case, Word.dll).
Hi Evan,
This is a month late and so you may have already solved this, but
here's how I do it. It's for Excel, not Word, but hopefully you'll get
the idea:
tlbimp "C:\Program Files\Microsoft Office\Office\MSO97.DLL"
/out
me.Interop.Office97.dll /namespace:Microsoft.Office97.Core
/keycontainer:MyKey /sysarray
tlbimp "C:\Program Files\Common Files\Microsoft Shared\VBA\VBEEXT1.OLB"
/out
me.Interop.VBIDE97.dll /namespace:Microsoft.Vbe97.Interop
/keycontainer:MyKey /reference
me.Interop.Office97.dll /sysarray
tlbimp "C:\Program Files\Microsoft Office\Office\Excel8.OLB"
/out
me.Interop.Excel97.dll
/namespace:Microsoft.Office97.Interop.Excel /keycontainer:MyKey
/reference
me.Interop.Office97.dll /reference
me.Interop.VBIDE97.dll
/sysarray
The basic idea is that you tlbimp each library, starting with those
that have no dependencies (in this case Office), and then libraries
that have dependencies reference the ones you just built.
Note that I'm strong-naming the generated interp assemblies with MyKey.
This is optional, but you probably want to do so.
This technique of choosing your own namespace, rather than using
Microsoft's namespaces, is an approach I'm experimenting with. I'm
hoping to do this to avoid namespace conflicts if my application
references IAs for multiple versions of Office, in order to be
compatible with really old versions of 97 while still being able to
take advantage of features in new versions like 2003, if the user's
machine happens to have that newer version.
Unfortunately, I've just discovered that tlbimp /namespace doesn't work
on MSO.DLL for Office XP and 2003, because that particular type library
has a custom attribute specifying Microsoft.Office.Core. This is bad
for my plan, because if my application references the Office IAs for
both versions -- XP and 2003 -- then I'm likely to get conflicts
because both IAs have the same namespace.
The only way I can see around this problem with the Office XP and 2003
IAs is to edit the IAs manually:
1. Generate the IA with tlbimp.
2. Output IL for it with ildasm.
3. Edit the IL, replacing mentions of the Microsoft.Office.Core
namespace with some unambiguously version-specific namespace.
4. Regenerate the IA with ilasm.
I haven't tried this yet. I think it will work, but I was googling to
see if otheres had run into my problem when I discovered yours
-- Peter Gummer