views:

143

answers:

3

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
+5  A: 

Have someone find the OFfice 2000 installer and put Office 2000 in development. If you don't have like environments you can't be sure that your code will work in production.

mrdenny
+2  A: 

I would tend to agree with comments that the cheapest solution is to install the same version of office, there are other times when you need to solve this problem too:

You can make an interface that provides the functionality needed to do the office interaction. Then you can make two separate modules that implement the same interface, one depending on office 2000, the other on 2003. You should probably put the interfaces in a third module.

In the code, you can instantiate the implementation by name instead of using regular "new". This means you can just switch modules for the different office versions. Your main project can only depend on the interface(s), and does not need to depend on office at all.

Office2000Module ----> Interfaces <------ Main application code
                         ^ 
                         |
Ofice 20003Module--------/
krosenvold
+1  A: 

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

Hans Passant