3

I am writing a Windows Phone app, at the beggining using VS 2010 Express for windows phone. Then I installed VS 2012 and i made a desktop app which consumed JSON/REST service using RestSharp. Due to lack of support for plugins in Express version, i got full VS 2010 Ultimate and installed Nuget. When I create a win phone library project, and i add a RestSharp package, it shows in References, but i cannot access any of it's classes (and using RestSharp is underlined in red color). Also, when i Remove it and add again from Add Reference i get an Incompatible reference error window:

RestSharp.WindowsPhone, Version=103.2.0.0, Culture=neutral, PublicKeyToken=null" is incompatible with 
Windows Phone 7.1
In order to add it yourself you should to change the project's terget to a compatible framework first.

It also appears if i change the target to WP 7.0.

Has anyone solved similar problem?

marcin32
  • 83
  • 2
  • 6
  • Ok, i have found similar problem http://stackoverflow.com/questions/5407461/vs2010-incompatible-reference-when-trying-to-add-reference but it hasn't solved mine problem. Also i have tested it on my friend's computer (he had Express for WP and now he also installed VS 2010 Ultimate) and he suffers from the same problem right now. – marcin32 Jul 17 '12 at 11:31

2 Answers2

5

In my case this was because there was a packages.config file in the project folder but not in the solution. This was why I could not add the reference again properly. Delete this file from the physical disk, and re-run your Install-Package command. It should add this correctly now.

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
Paul Devenney
  • 889
  • 6
  • 18
2

Are you using source control?

The it might be possible that you have not yet set the solution to enable package restore (NuGet documentation).

Right click on the Solution node in Solution Explorer and select Enable NuGet Package Restore.

After that Solution Explorer will contain a few items more and there will be a new folder packages that was automatically added to your solution folder. You will need this folder to add to your version control because it will contain your installed NuGet packages.

That's it.

If you want to know more, here's more details on what it (automatically) does for you:

It added a solution folder named .nuget containing NuGet.exe and a NuGet.targets MsBuild file. It also changed every project in the solution to import the NuGet.targets MsBuild task.

With this in place, any time a project is compiled, the build task will look at each project's packages.config file and for each package in that file, ensure that the corresponding package exists within the packages folder. For any missing package, the build task will download and unpack the package.

In the restore scenario, NuGet will grab the exact version when restoring a package. It will not perform any upgrades.

Additionally, if you have the latest NuGet version installed, will now find a new option unter Tools -> Options... -> Package Manager -> General -> Allow NuGet to download missing packages during build that I would also suggest to use.

The name says it all. If the solution is configured to use a certain NuGet package but the package is not yet installed on your development machine, NuGet will download it automatically for you when you do your next build.

Jens H
  • 4,590
  • 2
  • 25
  • 35
  • No, actually we are not using source control yet in this project. To be honest I was struggling for a few hours more with this problem, doing all sort of crazy thing in VS and in some point it started to work. I honestly don't know what has changed, tommorrow i might check it on my coworker's computer. Last thing I remember was making a couple of Clean Up's and Rebuilds. Anyway the problem is almost solved, I believe it is a VS2010 error. – marcin32 Jul 17 '12 at 22:58