none
Adding references between two Projects [Addin/Template] in a Solution RRS feed

  • Question

  • I've created a solution with two projects, a Word Addin and a Word Template.

    I have reusable code that I intend to put in the Addin, and I will eventually have a few different templates that reference classes/functions in the addin.

    However, I'm unable to add references between these two projects -- The "Projects" tab under the "Add Reference" dialogue is blank.

    I've been able to add a reference via the "Browse" dialogue -- but this seems rather hackish.  I'd hate if I deployed the solution and all the references break.

    Is it possible to add references between a Word Addin and a Word Template?

    Thanks!


    Friday, May 27, 2011 11:49 PM

Answers

  • I believe that, even though these are in the same solution, the VSTO runtime will load them into separate app domains. Thus, they aren't visible to each other. You'd need to use "Remoting" in order to communicate directly. There are some older discussions on this subject in the forum that you should turn up by searching that term.

    An alternative would be to create a "plain vanilla" DLL with the shared components. Since that wouldn't be loaded by the VSTO run-time it should be accessible in a normal way.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by tswaters Friday, June 3, 2011 3:15 AM
    Monday, May 30, 2011 6:29 AM
    Moderator

All replies

  • I believe that, even though these are in the same solution, the VSTO runtime will load them into separate app domains. Thus, they aren't visible to each other. You'd need to use "Remoting" in order to communicate directly. There are some older discussions on this subject in the forum that you should turn up by searching that term.

    An alternative would be to create a "plain vanilla" DLL with the shared components. Since that wouldn't be loaded by the VSTO run-time it should be accessible in a normal way.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by tswaters Friday, June 3, 2011 3:15 AM
    Monday, May 30, 2011 6:29 AM
    Moderator
  • In searching the MSDN on how to use "Remoting" I came across the following banner in a few places:

    This topic is specific to a legacy technology that is retained for backward compatibility with existing applications and is not recommended for new development. Distributed applications should now be developed using the  Windows Communication Foundation (WCF).

    I suppose I'll have to give the plain vanilla DLL a try.  I tried it out and I'm able to set up project references, so that's a win.

    Since this shared components will still need references to word types, objects, etc... Which reference(s) to Office/Word DLLs should I add to the vanilla class -- is it OK to keep the same references that are present in a generic 2007 office project template?

    ---

    Also, I've got a separate question -- this addin doesn't apply to all documents, just the ones created within the solution.  As such, each template in the solution runs some code on ThisDocument_New to add a document variable.  Then in the addin, I've got an event handler on Activate that checks for the presence of that document variable and, if found, does some stuff... Are you aware of an easier/better/more robust way to do this?

    Wednesday, June 1, 2011 2:27 AM
  • References: basically, the same ones you see in your VSTO project(s), yes.

    Document Variable isn't a bad idea, as that can't be accessed directly by the user. The only danger, then, would be whether a third-party component would ever do something. (Note: I've never heard of anything like this happening, but you never know...)

    Another possibility would be to insert a Custom XML Part, if we're talking Word 2007/2010. That could hold additional information if you need to store other things with the document. The CXP could be identified with your "proprietary namespace", making checking for its presence simple enough.


    Cindy Meister, VSTO/Word MVP
    Wednesday, June 1, 2011 5:36 AM
    Moderator
  • Ya know Cindy, you are hand-down the most super-person I have ever encountered on online forums.  Wherever I go, whatever post is linked to with some good information to read up on -- you seem to be the one answering everyone's questions about VSTO...  Thanks for that!

    ---

    My main concern with using doc variables actually was relating to third party developers overwriting my variable -- with it not present, or ovewritten as an unexpected value -- everything would basically break.  Maybe I am paranoid.  Actually now that I think about it the CXP would be much better.  

    When you said proprietary namespace, you mean XML Namespace on the CXP, right?  SelectByNamespace method sure would make that easy.

    ---

    Also, while I was searching around, I also managed to find a couple good MSDN blog posts that described how to use remoting with vsto and how to create a common class library.... may be handy to provide for anyone else finding this topic.


    Friday, June 3, 2011 3:14 AM
  • <<When you said proprietary namespace, you mean XML Namespace on the CXP, right?  SelectByNamespace method sure would make that easy.>>

    Yes, that's what I meant :-)


    Cindy Meister, VSTO/Word MVP
    Friday, June 3, 2011 8:11 AM
    Moderator