简体   繁体   中英

Visual Studio 2017 C# project with Microsoft.Office.Interop.Word 2016/365 coded and 2010 production

I'm coding one of my first projects in Visual Studio 2017 using the Microsoft Office Interop Tools to basically open some Word files, extract some content and export it to an XML file. I know that on the target machine Office should be installed and actually on that PC a 2010 installation is licensed, while on my PC I have a 365 suite.

The first build was working only on my PC, with missing references errors to the interop library on the production PC, so I've downloaded the Microsoft Office 2010: Primary Interop Assemblies Redistributable https://www.microsoft.com/en-us/download/details.aspx?id=3508 to include as a reference in my project, replacing the 2016 one.

First difficulty was: Once installed I cannot find the files on my drive, nor a reference inside visual studio, nor in the documentation. Is there any info about where to pick the dll?

So I unzipped from the cab the WORDPIA.DLL on an handy directory and referenced it in my project.

While is it working locally, it isn't yet on the production PC. I'm sure I'm missing a lot of points on this topic, VS & C# are not my territory, but I need some tips to finish the project.

Go back to the original project (or reference the version of the PIAs installed on your machine). The redistributable is intended for installing to an Office 2010 machine where the PIAs were not installed. It's not meant to be used in the manner you envision.

Now click each "interop" reference entry and look at the Properties window. There should be a setting for "Embed Interop Types". Set that to True. This should make the project version-independent as it will contain the PIA information your project uses.

在此处输入图片说明

Note that "embed interop types" was introduced with .NET Framework 4.0 and is not available for earlier versions of the Framework. If an earlier version is a requirement, then you have to use late-binding or develop your project using Office 2010.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM