Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional build based on version of MS Office installed

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
We have ourselves something of a problem. :(
We've built an application using C# (Visual Studio .NET).
In it we're making interactions with both MS Excel and MS Word [creating Word documents and reading spreadsheets].
On our development machines we have MS Office 2000 installed and as such have made the code work with these versions of Word and Excel.
One of our clients only has MS Office 97 installed on their machines.
If we run our version of the application on their client machines we get 'exception' messages when these elements of the code are run. [we're guessing the interaction now works differently]
We are now having to set up a development machine with (outdated) MS Office 97 installed on it in order to create re-builds of the application.

Is there any means by which we can create a version of the source code that builds the correct code dependent on the machine on which it is compiled ?
A conditional build of sorts ?

We don't really want to be in a position whereby we're tied down to one development machine (with Office 97 on it).

How can we best work around this issue ?
Thanks in advance.

Steve

 
would it not be easier to check what version of office it is in your code and then make different function calls based on the results?

building per office version means that you will have a different version of ur app for every version of office. surely a pain for the end user and yourselves?

Skute

"There are 10 types of people in this World, those that understand binary, and those that don't!"
 
The problem is having the methods for both Office 97 and Office 2000 in the same source code files.
If Office 2000 code is visible when compiling on a machine with 97 installed - the compiler fails to create a build and vice-versa.
And we cannot have both Office 97 and Office 2000 on the same machine.
So leaving boths sides of the code (uncommented) would result in no compiling regardless of the machine being built on.
Ideally we want some code blocks to be compiled under one situation (Office 2000 on machine) and other code blocks under another condition (Office 97 on machine).
Any thoughts ?
Steve
 
What you want is a design pattern known as a factory.

It allows you to have one class which knows how to instantiate various classes, based on what the caller wants. If the caller asks for a Office97 library, it instantiates it and returns it. If the caller asks for a Office2003 library, it gives them an instance of that.

In order to have different libraries for the various versions of MSOffice, you'll create separate assemblies for each version of Office (since each assembly will have a reference to the Office primary COM interop assembly).

Here's a good site with code:
[URL unfurl="true"]http://www.dofactory.com/patterns/Patterns.aspx[/url]

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top