Search code examples
.netvisual-studio-2010pathadd-inribbon

An Excel Ribbon via VSTO solution explorer folder structure vs. path in code


I am following this tutorial for adding an Excel Ribbon via VSTO.
My problem is exactly the same as this one. I have visited the links, but it didn't help me. The answer is very poor and leaves me clueless in terms of how to solve this issue.
If I add a Ribbon Item straight to the Project I am able to compile and run the add-in. However, when I add a new folder then stick a new item(Ribbon) inside of that folder I am getting an error. I think it's related to the path'ing.
Somewhere, somehow I have learned that Visual Studio 2012 uses an intelligent folder structure (sorry for this poor naming) which means that it looks for files in default directories etc. If you change the structure then you have to edit a file(i dont know which one) and specify your new path to it. I am suspecting the above to be the issue.

Solution Explorer folder structure:
Solution Explorer Folder Structure

The error msg:

> 'MyAddIn.Ribbon.ThisRibbonCollection' does not contain a definition
> for 'GetRibbon' and no extension method 'GetRibbon' accepting a first
> argument of type 'MyAddIn.Ribbon.ThisRibbonCollection' could be found
> (are you missing a using directive or an assembly reference?)

The code:

partial class ThisRibbonCollection
{
    internal MyCustomRibbon MyCustomRibbon
    {
        get { return this.GetRibbon<MyCustomRibbon>(); }
    }
}


My question is: What code do I have to modify (namespace?) in order to point the partial class to the right location?


Solution

  • Ha! I have just realised there is a very simple work around to this problem. I am sure there are other ways, possibly more complicated and requiring coding, to solve this issue but why would you want to complicate your life in first place? :) I think this solution generally applies to anyone with a similar problem.
    I remember reading ASP.NET 4.5 IN C# and VB.NET. The author introduces you to the Visual Studio in great detail and explains how to use the Solution Exlorer. I realized it was possible to move files around in the Solution Explorer while Visual Studio would automatically update all references for us.
    I was able to compile and run the Project when I added the file straight to the Project as a new item (Ribbon[Visual Designer]). When I created a new folder in the Project Solution called Ribbon and then right-clicked and added a new item I was getting error. So, instead of adding the new file to the Ribbon folder, I added it straight to the Project and then simply dragged it to the Ribbon folder. Boo! The project compiled and ran with no errors!
    I can't believe I haven't thought of it in the first place -> I guess I got too carried away following the tutorial...

    Steps:
    Add a new folder called Ribbon
    Adding a new folder to the Project

    Right click MyExcelAddIn > and a new item Ribbon (Visual Designer)
    Right click the

    Drag and drop myRibbon.cs into the Ribbon folder
    drag and drop
    compile and run! Enjoy