Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a project referencing "MS-Office Object Library" on multiple development machines

I'm using two computers, one has Office 2010 installed and the other has Office 2016. The first one is my main PC.

Let's say I started a project on the main PC. If I add a reference to any of the following:

  • Microsoft.Office.Interop.Word (Microsoft Word 14.0 Object Library).
  • Microsoft.Office.Interop.Excel (Microsoft Excel 14.0 Object Library).
  • Microsoft.Office.Interop.PowerPoint (Microsoft PowerPoint 14.0 Object Library).

..and then open the project on the second PC, Visual Studio will automatically select the applicable version for all of them (i.e., "Microsoft XXXX 16.0 Object Library") since "Embed Interop Type" property is set to true.

So far so good, but when I add a reference to Microsoft.Office.Core (Microsoft Office 14.0 Object Library), I can't get the same behavior, that is, when I open the project on the second PC, I find the reference with the same version (14.0) flagged with an icon indicating that the reference is missing along with warnings telling me the same thing (the reference cannot be found).

Obviously, if I remove the reference and replace it with the newer version (16.0), everything works fine except -of course- that I won't be able to open the solution on the main PC anymore.

So, my questions are:

  • Why doesn't it select the appropriate version for Microsoft.Office.Core like what happens with Interop.Excel, Interop.Word, etc?
  • Is there a solution for this so I can open the project seamlessly between the two computers?

Please note:

  • The main focus is not about running the application by the end user with different versions of Office (this have been asked and answered many times before). I'm more concerned about opening the solution/project on a secondary development machine with a different version of Office installed.

  • In case that's relevant, this is a WinForms application.


Update:

  • I tried copying the MSO.DLL file to a local 'lib' folder but whenever I add it as a reference, it shows "C:\Windows\assembly\GAC_MSIL\Office\14.0.0.0__71e9bce111e9429c\Office.dll" as the path of the reference. Then, no matter whether I disable/enable the Embed Interop Types property, it still doesn't compile on the secondary development machine.

  • Although I'm not quite sure I fully get Eugene's answer, it helped by giving me the idea of adding the PIA references in the Assemblies tab, not the COM tab and still have the Embed Interop Type property set to true. That actually seems to work but I'm not sure if not using the COM references might have any downsides. Does it?

like image 394
41686d6564 stands w. Palestine Avatar asked Oct 17 '22 17:10

41686d6564 stands w. Palestine


1 Answers

You need to copy interop assemblies (Microsoft Word/Excel/PowerPoint/Core 14.0 Object Libraries) to a local folder in the solution. And then you can add them as references, so they will be accessible on both machines and you will be able to open the project seamlessly between the two computers.

like image 143
Eugene Astafiev Avatar answered Oct 23 '22 16:10

Eugene Astafiev