I have an annoying problem in one of my projects where the production environment uses Microsoft Office 2000 and we only have Microsoft Office 2003 in the developement environment.
I use automation to do some manipulation of Word documents so to make this work in both the production and the developement environments i have to put a conditional compiler statement into the using-section of my code in all the files that uses automation.
#if DEVELOPEMENT using Word = Microsoft.Office.Interop.Word; #else using Office; #endif
Edit: I know the obvious solution is to get Microsoft Office 2000 onto the developement environment, but that is not easy if you want to do it the legal way.
I use Visual Studio 2005, so is there a more elegant way to avoid this conditional compiler statement?
Edit: The solution with using the TlbImp.exe tool from the SDK works beautifully, you just have to remember to give the generated file a strong name by generating a keyfile using the sn.exe tool else the Visual Studio wont compile the solution:
'c:\...\SDK\v2.0\Bin\TlbImp.exe' 'c:\...\Microsoft Office\Office10\MSWORD9.OLB' /keyfile:Office.snk /out:Office.dll
Locate a machine that has Office 2000 and .NET installed. Run this command on it:
Tlbimp ‘c:…\msword.olb’ /out:Word.dll
where … is the Office installation directory. Copy Word.dll to your dev machines. Add a reference to it in your project, make sure Copy Local is set to Yes (it is by default). You can now use ‘using Word’ for any version of Office. The Word.dll file must be deployed to the target machine in the same directory as your .exe