locked
How to reference a shared project in a shared project

    Question

  • Hi Community,

    Shared Projects seams to miss the references feature. How is it possible to build up the code in layers and reuse code from one shared project in another shared project?

    With the shared Project reference Manager I can add references from normal Projects to shared Projects, but not from shared Projects to shared Projects...???

    Kind regards, Markus


    Thursday, October 16, 2014 8:08 AM

Answers

  • I think you have misunderstood what a shared project is and how it is supposed to be used.

    Shared projects don’t have a binary output by themselves but their contents are imported by the platform projects and used as part of the build process to generate the Windows Store and Windows Phone application packages (.appx): http://blogs.msdn.com/b/visualstudio/archive/2014/04/14/using-visual-studio-to-build-universal-xaml-apps.aspx

    You should use class libraries if you want to share your code across different universal apps. Please refer to the above link for more information.

    Please also remember to mark all helpful posts as answer and/or helpful.

    Thursday, October 16, 2014 12:06 PM

All replies

  • You should add the reference to the other shared project from all your "normal" projects (for example the Win8 AND the WP8 projects) just like you added the reference to the first shared project.

    Please refer to the following page on MSDN for more information: http://msdn.microsoft.com/en-us/library/windows/apps/dn609832.aspx

    "For example, if your Windows Store app contained an assembly reference for a third-party library, and you move the associated code into the Shared folder, then you also have to reference the third-party library in the Windows Phone project."

    A shared project doesn't need any references as its contents are automatically included in all client projects and in their build output.

    Please remember to mark helpful posts as answer and/or helpful.

     

    • Proposed as answer by Magnus (MM8)MVP Thursday, October 16, 2014 12:23 PM
    Thursday, October 16, 2014 9:54 AM
  • Hello Magnus,

    thanks for the quick answer! I know this article. But what I want to do is seperate the shared code in different shared projects and use the code from one shared project in another. And I can not use the classes defined in shared project 1 from shared project 2 simply by referencing both projects in the client project. (The C# compiler is saying that I miss a reference...)

    Background:

    E.g.: Normally I build up a kind of framework with basic stuff. To use this in a universal app it should come into a shared project. Than I start developing a business layer. This layer also should be shared among the different client projects. But of course I want to use the framework stuff also in my business layer. And I want to use the framework stuff for all my apps/customers...

    Putting all shared code in one single shared project is fine for sample apps, but not for real world apps... And if it turns out good about around 90% of my code will reside in the shared area...

    Thursday, October 16, 2014 10:36 AM
  • What if you put your business logic code in a class library and a Add Shared Project Reference to this class library as described here?: http://marcominerva.wordpress.com/2014/04/22/how-to-share-code-among-different-universal-windows-apps/

    Thursday, October 16, 2014 10:53 AM
  • Hello Magnus,

    again - thanks for your answer!

    (maybe the solution is simple, but I dont see it)

    BUT: My problem is: I want to use the share code not only in the client projects but also in other shared projects.

    Lets say you have two shared projects: ProjectBase and ProjectBusiness

    In ProjectBase you define a class called NumberWizard which implements a Method called GetMagicNumber()

    In ProjectBusiness you need MagicNumbers. So you want to use the Method like this:

    var magicNumber = NumberWizard.GetMagicNumber();

    To make this working in normal projects you just set a reference from ProjectBusiness to ProjectBase and write a using statement...

    How to do this with shared projects? Both projects are shared projects and are in the same solution.

    Thursday, October 16, 2014 11:25 AM
  • I think you have misunderstood what a shared project is and how it is supposed to be used.

    Shared projects don’t have a binary output by themselves but their contents are imported by the platform projects and used as part of the build process to generate the Windows Store and Windows Phone application packages (.appx): http://blogs.msdn.com/b/visualstudio/archive/2014/04/14/using-visual-studio-to-build-universal-xaml-apps.aspx

    You should use class libraries if you want to share your code across different universal apps. Please refer to the above link for more information.

    Please also remember to mark all helpful posts as answer and/or helpful.

    Thursday, October 16, 2014 12:06 PM
  • Hello Magnus,

    OK, that's solving my problem. I just have to reference all shared projects in the main client project, because than the code of all projects is integrated into the main client project and than the compile is working. I knew the solution was simple...

    Thank you very much for your answers and your time!

    Markus

    Thursday, October 16, 2014 12:22 PM