The "SetOffice2007AddInRegistration" task failed unexpectedly

0

I have created a new C# project using a Word 2013 and 2016 VSTO Add-in template in Visual Studio 2015. I have not done any changes to the auto-generated project code in order to see how it will be built on my TFS 2015 Build Server. The build produced the following error:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets (315, 0)
The "SetOffice2007AddInRegistration" task failed unexpectedly. System.Runtime.InteropServices.COMException (0x800703F0): An attempt was made to reference a token that does not exist. (Exception from HRESULT: 0x800703F0) at Microsoft.VisualStudio.Tools.Office.Runtime.Interop.VSTOEENativeMethods.GetVSTOEEHandle() at Microsoft.VisualStudio.Tools.Office.Runtime.Interop.VSTOEENativeMethods.GetSolutionMetadata(String solutionInfoString) at Microsoft.VisualStudio.Tools.Applications.OfficeSolutionMetadata..ctor(String manifestLocation) at Microsoft.VisualStudio.Tools.Office.Runtime.AddInRegistryKeyManager.RegisterAddIn(Uri manifestUri, String addInName, String officeApplication, String friendlyName, String description, Int32 loadBehavior, String compatibleFrameworkXML, Boolean runLocal) at Microsoft.VisualStudio.Tools.Office.BuildTasks.SetOffice2007AddInRegistration.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

The Build Service is run as a domain account which is an administrator of the Windows Server 2012 where the Build Service is installed. The Visual Studio 2015 and Office 2016 are installed on this Windows Server.

When I build the project in Visual Studio 2015 on my local pc I have no errors at all. Please, help if you experienced the same problem in your work. Thank you.

c#
msbuild
visual-studio-2015
vsto
office-2016
asked on Stack Overflow Apr 27, 2016 by MBK • edited May 1, 2016 by MBK

2 Answers

1

This issue is not TFS related.

But I found a solution from Jens at this website, which should help you:

"

According to the MSDN Library SetOffice2007AddInRegistration "Defines an MSBuild task that creates or removes registry keys that are needed to run or uninstall an add-in for the 2007 Microsoft Office system." So I checked the registry and figured out that the only entries that were still present were the ones under HKEY_CURRENT_USER\Software\Microsoft\VSTO\SolutionMetadata where VSTO caches metadata for solutions. I deleted all keys and subkeys (your existing solutions will still work, it's just cached metadata) and my solution compiled successfully.

"

answered on Stack Overflow Apr 28, 2016 by Cece Dong - MSFT
1

As I have spent significant chunk of my time trying to resolve this error and getting to nowhere, I would like to share my experience with other people. I have a suspicion that MSBuild has a bug when it is run for XAML build definitions of Office Addin projects.

I created a brand new Word 2016 Addin project in Visual Studio 2015. No custom code. The project had only auto generated code. The Visual Studio built the project with no errors. I run the build with the MSBuild Diagnostic output Verbosity option selected.

After that, I run the MSBuild program from the command line with the same parameters that TFS Build Server run the build. The only difference was the the Diagnostic verbosity log option to create a detailed log. I compared two logs produced by Visual Studio and MSBuild. The MSBuild log indicated that workflow never got to the step of unregistering the Addin. Actually, it tried to register the Addin without unregistering. The Visual Studio log showed that the Visual Studio build unregistered the Addin and registered it after that successfully.

Learning the TFS 2015 features, I found out about Agent Pool and Build Agents. I realized that instead of running MSBuild for XAML defined builds, the TFS 2015 Build Agents use Visual Studio to build the application. So, I set up the Agent Pool and Build agent on my build server and, voila, the Addin was built successfully!

The conclusion is if you have XAML defined build for your Addin project, do not use it in TFS 2015. Create a new TFS build definition using Agent Pool features provided in TFS 2015. This will guarantee that your build will be done on TFS build server exactly like on your PC in Visual Studio environment.

answered on Stack Overflow May 26, 2016 by MBK • edited May 27, 2016 by MBK

User contributions licensed under CC BY-SA 3.0