C# Visual Studio: How to have multiple developers on a solution that references Office?

China☆狼群 提交于 2019-12-06 08:33:26

问题


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.


回答1:


Abstract your code so that ALL of the code that touches Office is in a separate project. Then you can have two projects - one for Office 11 and one for Office 12. Then reference both projects from your application. If the classes both implement a common interface, then you can use a factory pattern to instantiate the appropriate one and use the features without having to recompile.




回答2:


You might be able to use late binding for this.

Have a look here: http://www.hanselman.com/blog/BackToBasicsVarDim.aspx

or here: http://support.microsoft.com/kb/302902




回答3:


late bind to whichever type library is present, and code against the older interfaces - if youre using the v11 interfaces, you should be ok when you ve got v12 on a machine.




回答4:


If you abstract the interface to a separate project you can then then use vb.net and its built in late binding support to provide the functionality and manage resources.



来源:https://stackoverflow.com/questions/403338/c-sharp-visual-studio-how-to-have-multiple-developers-on-a-solution-that-refere

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!