none
How to build app compatible with Office 2007 -- "assembly office Version..."??? RRS feed

  • Question

  • EDIT: This has been solved by a combination of the replies, solution is summarized at bottom.

    Thank you to everyone who responeded.

    I'm working on an update to an existing application used internally in my company.  However, when I build and publish, the employees that use the application cannot install due to the error:

    "Unable to install or run the application. The application requires that assembly office Version 15.0.0.0 be installed in the Global Assembly Cache (GAC) first."

    This happens on machines that still have Office 2007.  For the time being, it is necessary to run the application on these machines with 2007 Office.  The prior version of the application installs and runs fine on their machines.

    What exactly do I need to do to build my app so that it is compatible with Office 2007?  (If it makes a different, the machines are running windows 7).

    I am assuming it has something to do with changing the references in the project properties, but I do not know exactly what I need.  Or if I'll need to download the older versions of libraries and where to get them.

    I am guessing the relevant project references are following (though maybe not the last one?):

    Microsoft Excel 15.0 Object Library COM 1.6.0.0 Microsoft Graph 15.0 Object Library COM 1.6.0.0 Microsoft Office 15.0 Object Library COM 2.5.0.0 Microsoft Word 15.0 Object Library COM 8.4.0.0 Microsoft Visual Basic for Applications Extensibility 5.3 COM 5.3.0.0

    I am using Visual Studio Ultimate 2013.

    I am wondering if Visual Studio would have automatically updated these library references to what is installed on my machine, as I did not manually change them.  (But it is possible that some other developer made changed the library references in project source in a prior attempt to make the app work with later version of Office)

    I did try opening and building the project in Visual Studio 2010, but it still uses the 15.0 versions on my machine (which has Office 2013 installed).

    When I search in the add references, I think I probably need the 12.0. versions of the above.  But doing a search I find assemblies that seem like they might be right (such as "Microsoft.Office.Interop.Word 12.0.0.0") , but they are .NET rather than COM, so I am not sure.  Under COM I only find the 15.0 versions.

    So where/how to I get the right libraries and make them available to reference in visual studio.  And/or are there other things I need to do?

    Thanks.

    EDIT:  SOLUTION:

    The two critical pieces of information needed were 

       (1) find the interop library(ies) in the Solution browser, open the properties & set the "Embed Interop Type" to True.

       (2) In order to have that library property "Embed Interop Type" available, must first set the target framework in project properties to 4.0 or later.

    Red herrings: installing Office 2007 to get older libraries, installing Office 2007 PIA's (note, with VS 2013 & Office 2013 all the libraries needed are already there).  No need to copy any .dll files or otherwise track them down.

    Additional note:  if necessary to build for office 2007 & framework 3.5 and does not need to be compatible with later versions of office, then need Office 2007 installed on dev machine rather than Office 2013.



    Wednesday, July 2, 2014 7:30 PM

Answers

  • Hi Scott,

    Do you want to run the application that referenced Office 15.0 PIA on a machine that installed Office 2007?

    If so, please make sure that "Embed Interop Type" of this component is true.

    I created a Windows form application through VS 2013 and added a reference named "Microsoft.Office.Interop.Excel 15.0". I typed some code in a button click event as below:

    private void button1_Click(object sender, EventArgs e)
            {
                Excel.Application app = new Excel.Application();
                Excel.Workbook wb = app.Workbooks.Open(@"D:\1 - Copy.xlsx");
                app.Visible = true;
            }

    After that, I published and installed this application on a Windows 7 machine which had installed Office 2007.

    The application worked fine for me and I would find the workbook was opened.

    Does this make sense?


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 3, 2014 7:17 AM
    Moderator
  • What is the target .net framework for your add-in? The property is available starting from .Net 4.0.
    Thursday, July 3, 2014 8:55 PM

All replies

  • Hello Scott,

    You are on the right avenue. To use the features of a Microsoft Office application from an Office project, you must use the primary interop assembly (PIA) for the application. The PIA enables managed code to interact with a Microsoft Office application's COM-based object model. So, the add-in project should contain PIA references to the oldest Office version you need to support. The Running Solutions in Different Versions of Microsoft Office article in MSDN states the following:

    If you developed solutions for Office 2010, you can run the same solutions in Microsoft Office 2013. If your customer base uses the 2007 Microsoft Office system, you can use Visual Studio 2013 to develop solutions that work in all three versions of Office. In this scenario, the solution will run without errors in the 2007 Microsoft Office system only if the solution doesn’t use features that are new in later versions of Office. Microsoft Office applications can also run solutions that were created by using a previous version of Visual Studio.

    You can download Office 2007 PIAs separately - 2007 Microsoft Office System Update: Redistributable Primary Interop Assemblies . Read more about PIAs in MSDN - Office Primary Interop Assemblies .

    Wednesday, July 2, 2014 8:00 PM
  • Thanks for the quick response.

    The downloaded PIA's are not (yet) helpful.  Note the installation requirement:

    Minimum system requirements to install the Office 2007 Primary Interop Assemblies are:
    1	A Microsoft Office System 2007 product
    2	.NET Framework 1.1 or higher

    I have Office 2013 on my development machine, not Office 2007.

    EDIT:  I am not sure if this makes a difference but the application is a forms app which *builds* word and excel documents, it is not an "app for office" or office add-in.

    Wednesday, July 2, 2014 8:30 PM
  • This is getting extremely frustrating.

    I installed Office 2007... now in visual studio project properties references, I get "Office 12.0 Object Library", etc., listed under COM.  But if I use this, it still appears to reference the 15.0 (office 2013) library not the 12.0.  When I try to install the application on machine with Office 2007, it still gives the same error -- that the 15.0.0.0 version is needed.

    Another odd thing is, if I select the 15.0 Object Libraries in references, it now says "<The system cannot find the reference specified>".  Note that I still have Office 2013 -- I installed Office 2007 side-by side with it.

    Please excuse a rant, but how hard should it be to select which version of libraries I want to reference?

    Last note:  I did install the PIA's downloaded from the link provided  2007 Microsoft Office System Update: Redistributable Primary Interop Assemblies    but it makes no difference that I can see.  There are no other items listed to add in references.

    Wednesday, July 2, 2014 10:41 PM
  • bump
    Wednesday, July 2, 2014 10:41 PM
  • Hi Scott,

    Do you want to run the application that referenced Office 15.0 PIA on a machine that installed Office 2007?

    If so, please make sure that "Embed Interop Type" of this component is true.

    I created a Windows form application through VS 2013 and added a reference named "Microsoft.Office.Interop.Excel 15.0". I typed some code in a button click event as below:

    private void button1_Click(object sender, EventArgs e)
            {
                Excel.Application app = new Excel.Application();
                Excel.Workbook wb = app.Workbooks.Open(@"D:\1 - Copy.xlsx");
                app.Visible = true;
            }

    After that, I published and installed this application on a Windows 7 machine which had installed Office 2007.

    The application worked fine for me and I would find the workbook was opened.

    Does this make sense?


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 3, 2014 7:17 AM
    Moderator
  • >  I am not sure if this makes a difference but the application is a forms app which *builds* word and excel documents, it is not an "app for office" or office add-in.

    Yes, I am talking about a winform app. You need to install PIAs for Office and then replace references with the newly installed ones. Don't forget to include them to the installation package or use the Embed Interop Types property for emitting interop types into the add-in assembly.

    Thursday, July 3, 2014 10:28 AM
  • You need to replace references in your project. Please see my previous message there.
    Thursday, July 3, 2014 10:28 AM
  • Yes, I did that, as stated in my reply above.
    Thursday, July 3, 2014 3:57 PM
  • I feel like this is getting closer to an answer.

    However, there is no "Microsoft.Office.Interop.Excel 15.0" available to add to the references.  Could you tell me exactly what to look for in [project]->Properties->references->Add... ?  And if what I am looking for is not there, how do I get it?

    What I have available in ...references->Add are items such as

    under COM:  Microsoft Excel 15.0 Object Library
         (version 1.8.0.0)
    
    under Assemblies:  "Microsoft.Office.Interop.Excel" 
         (versions 12.0.0.0 and 14.0.0.0)
         Note: no version number in the actual name)
    

    I am currently referencing the "COM" object library (this also appears to be what visual studio automatically pulls in as a reference).

    In solution explorer, this apparently shows up as "Microsoft.Office.Interop.Excel".  If I open the properties as you have done in your screen capture is shows a version of "1.8.0.0" not "15.0.0.0".  

    Finally, there is no "Embed Interop Type" setting.  Several other properties that appear in your screen capture do are not listed in mine.

    Thursday, July 3, 2014 6:47 PM
  • "embed interop types" property does not exist. 

    See my reply to George Hua.

    Edit:  Also note that it is not possible to install 2007 PIA's with Office 2013.  I have search extensively and found no indication of 2013 PIA's.  

    I did try installing Office 2007 (side by side with 2013) and then I installed the 2007 PIA's.  And I *did* change the references.

    The only way I succeeded creating a publish compatible with Office 2007 was to have *only* Office 2007 installed on my development machine.  But this is not an acceptable long term solution.

    Thursday, July 3, 2014 8:23 PM
  • What is the target .net framework for your add-in? The property is available starting from .Net 4.0.
    Thursday, July 3, 2014 8:55 PM
  • Hi Scott,

    You could find the DLL through path on your machine.

    You can copy this DLL into your project and add a reference from this folder.

    Hope this helps.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, July 4, 2014 1:44 AM
    Moderator
  • You need to copy interop assemblies locally and then reference them instead.

    The "Embed Interop Type" property of references is available starting from .Net 4.0.

    Friday, July 4, 2014 9:47 AM
  • Hi Scott

    "embed interop types" property does not exist. 

    See my reply to George Hua.

    Edit:  Also note that it is not possible to install 2007 PIA's with Office 2013.  I have search extensively and found no indication of 2013 PIA's.  

    I did try installing Office 2007 (side by side with 2013) and then I installed the 2007 PIA's.  And I *did* change the references.

    The only way I succeeded creating a publish compatible with Office 2007 was to have *only* Office 2007 installed on my development machine.  But this is not an acceptable long term solution.

    The only "correct" way to write software that works with Office is to have only one version of Office installed on your machine. This is by design and is not unusual for COM applications. (And it's one reason .NET was developed - to enable side-by-side versioning.) While an end-user can often work with parallel versions installed, you run into all kinds of problems when writing code, especially when you have to rely on PIAs. One reason for this is the way the type libraries are registered in Windows, another is the way a newer set of PIAs is designed to handle calls to older versions.

    For this reason, most Office developers use virtual machine software in order to support programming with multiple software versions.

    I haven't read this thread in detail, but while I find a number of mentions from people trying to help you about .NET 4.0 no where do I see what version of Visual Studio you're using or which version of the .NET Framework you're targeting. That information would be useful in order for us to provide optimum assistance.

    If you CAN use .NET 4.0 then you have a fairly simple way around your problem. If you cannot and you also don't use virtual machine software, then your only recourse is to use "late binding". How difficult this is depends on which programming language you use - another fact you haven't mentioned in this discussion, as far as I can see...

    Also, please note that this discussion is not in the correct forum as you're not using the VSTO technology. At some point, it needs to be moved to the General Office Development forum...


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, July 7, 2014 3:19 PM
    Moderator
  • Thanks for the response.

    I did piece together the solution (see edit of OP).  But I have not had a chance to come back and mark as answered or summarize the relevant bits of information I needed.

    FWIW, I did provide VS version in OP.

    You are right I didn't mention .net framework, as it took a while to even realize it was relevant.  I'm new enough to .net that framework version is not something I automatically think of (probably will from now on).

    Pretty sure language was not likely relevant at least between VB or C#, which I imagine most would assume anyway, but using VB as it happens.

    As to which forum this should be in, happy to have it moved.  This one seemed more likely, as it mentions both visual studio and office.  Had no idea whether the libraries involved fell under "tools for office" or something else.

    Wednesday, July 9, 2014 9:42 PM
  • Look for Microsoft.Office.Core and Microsoft.Office.Excel on the solution explorer pane, right click on each to view properties then set Copy Local = True. Rebuild your app again and deploy.
    Monday, December 22, 2014 10:44 AM