12

I'm having an issue with adding a dll reference to a shared project. As seen in the picture below I have a Universal solution with a project for windows and a project for windows phone.

Solution

In the HubApp1.Shared project I need to add a reference for some code in Class.cs. I will be using Class.cs in both the Windows project and the Windows Phone project. I have scoured Bing for how to fix this and I couldn't find anything.

James Esh
  • 2,219
  • 1
  • 24
  • 41

2 Answers2

11

You must add the reference in both WP and Windows project.

The reason for this is that shared project is not compiled into any output DLL - it is compiled into the project that references it, so it cannot reference any other project types except other Shared Projects.

Community
  • 1
  • 1
Ondřej Kunc
  • 1,087
  • 9
  • 17
  • Problem is, I need that dll in Class.cs which is in the shared project... If this isn't possible, we don't need the windows phone app for a while yet, we can just wait on Windows 10, which, of course, will solve all our problems. :) – James Esh May 04 '15 at 12:50
  • 3
    If you add that reference to both WP and Windows projects, then you can use this dll in shared project. That's because shared project is basically part of the WP or Windows project which is linked during compile time. Moreover if you add this dll only to let's say WP project and use some code from that dll in your shared project, then it will work only in WP and on Windows you would need to wrap this between `#if WINDOWS_PHONE_APP` and `#endif` - otherwise it won't compile. – Ondřej Kunc May 04 '15 at 13:14
0

I know this is an old question but I had a similar problem with a shared project. I needed a class in the shared project to use ConfigurationManager and the normal way would be to add a reference to the project, but you can't do that with a shared project.

In my case the solution was so simple it should have been obvious (but I was overthinking it!) - just give the full reference when using the configuration manager - EG:

var someVal = System.Configuration.ConfigurationManager.AppSettings["someKey"];

Not very elegant but simple enough.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mick
  • 141
  • 9