3

When I add a reference to Office COM Library, I to go:

  • References
  • Add Reference
  • Select the COM tab
  • Select Microsoft Office 12.0 Object Library

And magically named reference appears:

Microsoft.Office.Core

The Project.csproj file shows the details of the reference:

<COMReference Include="Microsoft.Office.Core">
   <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
   <VersionMajor>2</VersionMajor>
   <VersionMinor>4</VersionMinor>
   <Lcid>0</Lcid>
   <WrapperTool>primary</WrapperTool>
   <Isolated>False</Isolated>
</COMReference>

i check the project into source control, and now nobody else can build the solution; they do not have Office 12, they only have Office 11.

Another guy checks out the .csproj file, deletes the reference to:

Microsoft Office 12.0 Object Library

and re-adds the COM reference as:

Microsoft Office 11.0 Object Library

After that, and new reference appears in the Solution:

Microsoft.Office.Core

and the Project.csproj file shows the details of the reference:

<COMReference Include="Microsoft.Office.Core">
  <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
  <VersionMajor>2</VersionMajor>
  <VersionMinor>3</VersionMinor>
  <Lcid>0</Lcid>
  <WrapperTool>primary</WrapperTool>
  <Isolated>False</Isolated>
</COMReference>

Note: Readers who read the question will understand the problem. It's the same type library, but version 2.3 as opposed to version 2.4.

The project is then checked into source control, and now developers with Office 2007 (and Office 2000 for that matter) cannot build it, because Visual Studio cannot resolve the reference to:

{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}\2.3\0\primary

We obviously need a version independant way to reference Office.

How do we reference the version of Office that the developer building it on his machine has intsalled?

How do we have multiple developers work on a solution that references Office?


Note: This question is identical to, but fundamentally different from, another Stackoverflow question How to use Office from Visual Studio C#?

That question deals with the entire set of problems from trying to use Office from Visual Studio. This question only focuses on one specific problem.

4

4 回答 4

5

抽象您的代码,以便所有涉及 Office 的代码都在一个单独的项目中。然后您可以有两个项目 - 一个用于 Office 11,一个用于 Office 12。然后从您的应用程序中引用这两个项目。如果两个类都实现了一个通用接口,那么您可以使用工厂模式来实例化适当的接口并使用这些特性而无需重新编译。

于 2008-12-31T16:19:40.787 回答
1

您可能可以为此使用后期绑定。

看看这里: http ://www.hanselman.com/blog/BackToBasicsVarDim.aspx

或在这里:http: //support.microsoft.com/kb/302902

于 2008-12-31T16:29:45.557 回答
0

后期绑定到存在的任何类型库,以及针对旧接口的代码 - 如果您使用的是 v11 接口,那么当您在机器上安装 v12 时应该没问题。

于 2008-12-31T16:32:47.453 回答
0

如果您将接口抽象为一个单独的项目,那么您可以使用 vb.net 及其内置的后期绑定支持来提供功能和管理资源。

于 2008-12-31T16:36:05.403 回答