Compiling builds that have Microsoft Excel in TFS

2019-02-28 16:14发布

问题:

I am trying to compile a project in VB.net 2010 that uses Microsoft Excel dll at some points. It works all fine when I compile from my computer, but when I use TFS to queue a new build, I get the error that Microsoft.Interop.Excel... are not defined. I installed Microsoft Office 2010 directly on the TFS server but I still get the same error.

Are there any configuration I must perform for this to work?

Edit:

Typical error message you will see on a Build:

Error BC30002: Type 'Excel.Worksheet' is not defined.

Error BC30002: Type 'Microsoft.Office.Interop.Excel.Application' is not defined.

Warning BC40056: Namespace or type specified in the Imports 'Microsoft.Office.Interop' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

回答1:

You need to include the dll's in a lib folder that is kept in TFS and reference the dll's from that location, in your project not wherever else they have been installed.

Edit:

Developers typically reference the Interop PIA's from C:\Program Files (x86)\Microsoft Visual Studio 14.0\Visual Studio Tools for Office\PIA\Office15 and this folder wont exist on the server.

You need to copy these files, eg Microsoft.Office.Interop.Excel.dll to a lib or refs folder in source control and reference these DLLs from your solution instead of the ones in the PIA path.

Also note, same goes for DLLs from the Reference Assemblies folder, eg:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Windows.Forms.dll



回答2:

Just in case it makes a difference, you mentioned your TFS server, but that is not necessarily where your build is occurring.

The build report (likely where you saw the error in TFS) should indicate the path to where the build machine is storing the source code - by default the path is somewhere under c:\build. A good first step would be to go to the desktop of the machine where the build agent is installed (You can see a list of the build agents by right-clicking on the Builds node in Team Explorer and choosing Manage Controllers...) Once you are on the desktop of the correct machine, copy the source folder from that path to some other place on the same machine and open the new copy solution file and build it in Visual Studio. Troubleshoot the build as if you would on your local machine - something is missing on that build machine and these steps should help you find it more easily.



回答3:

You should try to run the build on the build machine manually. First in visual studio, and then with msbuild. This should fail, but but you're likely to get a better idea of what is going on, and why it's failing. It's possible that your excel dll isn't located in the same place as it is on your own machine.