20

I'm trying to make a Universal App (Windows 8.1 & Windows Phone 8.1) and i need to deserialize Json with Json.NET library.

But i can't add a NuGet or dll reference to my Shared Project, i can do this only in Windows 8.1 and Windows Phone 8.1 project. I need this in my Shared project to prevent code duplication.

I'm using Visual Studio 2013.2 Final

Rightclick doesn't propose to manage Nuget Packages, and Project tab doesn't have "Add reference" item

How to do this ?

Kara
  • 6,115
  • 16
  • 50
  • 57
alvinmeimoun
  • 1,472
  • 1
  • 19
  • 38
  • What is the type of your Shared Project? I suspect it needs to be a Universal Class Library. It's not clear where Json.NET comes into your question... – Jon Skeet May 14 '14 at 15:06
  • I need Json.Net in library package to use my custom HttpClient with Json deserialization in my Windows Phone 8.1 and Windows 8.1 app. It's generated Shared Project (create a new project > Windows Store Apps > Empty Application (Universal)) – alvinmeimoun May 14 '14 at 15:08
  • Right, but where does that come into adding a reference to your shared project? – Jon Skeet May 14 '14 at 15:09
  • So your "shared project" is actually your app? That's confusing naming - I assumed it was a class library shared by two or more other projects. If you mean "my application project" then the issue is probably that Json.NET simply hasn't released a Universal Class Library NuGet package yet. – Jon Skeet May 14 '14 at 15:10
  • To be used in shared project, i need to link library to it. If i link to Windows Phone project, i can only use the library in Windows Phone project and not in Shared Project – alvinmeimoun May 14 '14 at 15:11
  • Main post edited with screenshot of project explorer and details – alvinmeimoun May 14 '14 at 15:21
  • Okay, the bit about Add Reference not being available is definitely the most important information, which was missing before. That's *not* Json.NET specific, obviously... – Jon Skeet May 14 '14 at 16:13
  • The `Shared` project in Universal Apps can not contain references or NuGet packages`. To be able to use a NuGet package in the `Shared` project you need to add the DLL or NuGet package to all projects referencing the `Shared` project (currently just the Windows and Windows Phone project, soon Xbox as well), then you will be able to use it in the `Shared` project. – Mikael Dúi Bolinder May 19 '14 at 17:50
  • @dandan78 please un-on-hold this. – Mikael Dúi Bolinder May 19 '14 at 17:52
  • This question should be reopened as the information in it is sufficient to answer (I knew the answer after I finished reading, and its exactly what the accepted answer says). – Andy Apr 22 '15 at 14:14

1 Answers1

20

Universal Shared project doesn't need to have any references/packages. Its concept is simplification and generalization of "Add as Link" option. You can try to install that packages (I suggest, PCLs) to both Win8 and WP8 projects and that probably will work, because Shared project uses, for example, Windows Store API without link to it.

Oleksandr Zolotarov
  • 919
  • 1
  • 10
  • 20
  • 1
    Added Json.Net to Windows 8.1 and Windows Phone 8.1 projet, worked ! thanks !! – alvinmeimoun May 21 '14 at 09:39
  • This is correct; shared projects don't generate an assembly, instead its just a container for Add as Link files (so you don't need to keep Add as Link for every new file in all your projects you want to do so in, you just add it to this new project type). – Andy Apr 22 '15 at 14:15