Assembly binding error when building Office add-in: "FindRibbons" task failed unexpectedly
.net, c#, jenkins, msbuild, visual-studio-2012
Solution
This has worked for me every time I upgrade Visual Studio - I don't use ribbons.
This worked for my solution, but use at your own risk:
Open the following file in an XML editor (make a backup first): `C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets` (the v10.0 part may be different for you, e.g., it might be v14.0)
Remove the following section:
<FindRibbons AssemblyName="$(AbsolutePathToCustomization)" TargetFramework="$(TargetFrameworkVersion)">
<Output TaskParameter="RibbonTypes" ItemName="RibbonTypesCollection"/>
</FindRibbons>
Replace all occurrences of `"@(RibbonTypesCollection)"` with the empty string `""`
Save the file and restart the visual studio
Problem
We're trying to set up a Jenkins (build server) job to build our Office add-in based on VSTO. However, I keep getting a strange error that fails the build process after the DLL is copied to the `bin` directory of the project: ``` Error 11 The "FindRibbons" task failed unexpectedly. System.IO.FileNotFoundException: Could not load file or assembly 'MyAddIn, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. File name: 'MyAddIn, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ``` So the problem is that the "FindRibbons" task, triggered by the Office add-in build target, has successfully identified the MyAddIn DLL as being an Office Add-In, but is not able to locate and load it! Any ideas? I'd love to be able to debug the FindRibbons task directly but hooking into and debugging the compile process seems a little extreme... Here are some observations: - In our build server's Fusion logs for binding the MyAddIn assembly it looks like it's looking in the folder where MSBuild.exe lives (`C:\Windows\Microsoft.NET\Framework\v4.0.30319\`) and nowhere else. On my dev machine, there is no Fusion log entry for MyAddIn! But the build process succeeds and Kivo works fine. - On both my dev and build machines I also have Fusion log entries for `WhereRefBind!Host=(LocalMachine)!FileName=(PresentationCore.dll)` and `ExplicitBind!FileName=(MyAddIn.dll)` which show the binding succeeding. - This error comes up on the build server whether I use Visual Studio or MSBuild from the command line to build the project. - I've ensured that the .NET/MSBuild/VS2012 versions are identical on both my dev machine and the build server and the error still occurs. The only difference seems to be that the build server is running Windows Server 2012 (since it's Azure, and we can't spin up a Windows 7 image).