Nuget installs old version of package Newtonsoft.Json because of WebAPI dependency - asp.net-web-api

I have a website and dll project.
In dll packages.config I used package:
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net451" />
In web site packages.config I use package:
<package id="Microsoft.AspNet.WebApi" version="5.1.2" targetFramework="net451" />. This package has dependency "Newtonsoft.Json with version >= 4.5.11"
I added also line:
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net451" />
when I launch "Update-Package -ReInstall" nuget checks that Microsoft.AspNet.WebApi depends on Newtonsoft.Json, then nuget overwrites web site packages.config with line
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net451" /> and copies Newtonsoft.Json 4.5.11 into "bin" folder of site.
Also bin folder has my dll that depends on fresh version of newtonjson and it does not work..
I tried command "Update-Package -Reinstall -IgnoreDependencies". It helped partially: now I have 6.0.3 in website/bin. But there are 2 issues: should all developers on project use only "Update-Package -Reinstall -IgnoreDependencies"? They cannot launch update of nuget from GUI?
Project that not start, some dll references Newtonsoft.Json 4.5.0 (I have no exact error message because of using dependency injection).
Does anyone know:
* how to normally tell to nuget to download newtonsoft 6.0.3 to work it normally in gui? Is there any option in packages.config for this?
* if I use newtonsoft json 6.0.3, should i use bindingRedirect to fix version on assembly for webapi?
Thanks a lot!!!

OK, I found the reason of issue
After editing packages.config for dll project and Update-Package -Reinstall command for dll project, nuget downloaded right version of Newtonsoft.Json (6.0.3) for dll project, but did not refresh path in references of project. Thus solution - do not edit packages.config manually. Only launch nuget commands from package manager console or gui.
Yes, bindingRedirect helped for the second problem

Related

Could not install package 'Xamarin.GooglePlayServices.Maps 60.1142.1' [duplicate]

I am trying to use google maps on my xamarin forms application. I installed Google.forms.maps. With that installation, I got below packages:
<package id="Xamarin.GooglePlayServices.Base" version="42.1021.1" targetFramework="monoandroid71" />
<package id="Xamarin.GooglePlayServices.Basement" version="42.1021.1" targetFramework="monoandroid71" />
<package id="Xamarin.GooglePlayServices.Maps" version="42.1021.1" targetFramework="monoandroid71" />
<package id="Xamarin.GooglePlayServices.Tasks" version="42.1021.1" targetFramework="monoandroid71" />
As soon as I start running the application, these dll's go away from android project reference and I get the error
Severity Code Description Project File Line Suppression State
Error Did not find reference matching RestoreAssemblyResources AssemblyName metadata 'Xamarin.GooglePlayServices.Tasks' app1.Android
Did not find reference matching RestoreAssemblyResources AssemblyName metadata 'Xamarin.GooglePlayServices.Base' app1.Android
Did not find reference matching RestoreAssemblyResources AssemblyName metadata 'Xamarin.GooglePlayServices.Maps' app1.Android
Did not find reference matching RestoreAssemblyResources AssemblyName metadata 'Xamarin.GooglePlayServices.Basemant' app1.Android
I googled for this error and tried to add these packages separately using nuget so I did this
Install-Package Xamarin.GooglePlayServices.Base -Version 60.1142.0
I got an error saying
Install-Package : Could not install package 'Xamarin.GooglePlayServices.Base 60.1142.0'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v7.1', but the package does not contain any
assembly references or content files that are compatible with that framework. For more information, contact the package author.
so I tried doing this:
Install-Package Xamarin.GooglePlayServices.Base -Version 29.0.0.1
I got the same error as I got with nuget package version 60.1142.0
I am using Visual studio 2017 enterprise version.
any help in this regards will be appreciated. Below are the target for android project:
My target framework is like this:
and The sdk Picture is like this:
Below is the visual studio Help-> about window.
Generic message:
Could not install package 'Xamarin.XXXXXXX'. You are trying to install this package into a project that targets 'MonoAndroid,Version=vX.X'
Specific message:
Could not install package 'Xamarin.GooglePlayServices.Base 60.1142.0'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v7.1'
Change your Xamarin.Androidproject to target at least MonoAndroid 8.0 as Xamarin.GooglePlayServices.Base v60.1142.0 has a dependency on 8.0
Nuget: Xamarin.GooglePlayServices.Base/60.1142.0
Dependencies

missing xamarin.googleplayservices references

I am trying to use google maps on my xamarin forms application. I installed Google.forms.maps. With that installation, I got below packages:
<package id="Xamarin.GooglePlayServices.Base" version="42.1021.1" targetFramework="monoandroid71" />
<package id="Xamarin.GooglePlayServices.Basement" version="42.1021.1" targetFramework="monoandroid71" />
<package id="Xamarin.GooglePlayServices.Maps" version="42.1021.1" targetFramework="monoandroid71" />
<package id="Xamarin.GooglePlayServices.Tasks" version="42.1021.1" targetFramework="monoandroid71" />
As soon as I start running the application, these dll's go away from android project reference and I get the error
Severity Code Description Project File Line Suppression State
Error Did not find reference matching RestoreAssemblyResources AssemblyName metadata 'Xamarin.GooglePlayServices.Tasks' app1.Android
Did not find reference matching RestoreAssemblyResources AssemblyName metadata 'Xamarin.GooglePlayServices.Base' app1.Android
Did not find reference matching RestoreAssemblyResources AssemblyName metadata 'Xamarin.GooglePlayServices.Maps' app1.Android
Did not find reference matching RestoreAssemblyResources AssemblyName metadata 'Xamarin.GooglePlayServices.Basemant' app1.Android
I googled for this error and tried to add these packages separately using nuget so I did this
Install-Package Xamarin.GooglePlayServices.Base -Version 60.1142.0
I got an error saying
Install-Package : Could not install package 'Xamarin.GooglePlayServices.Base 60.1142.0'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v7.1', but the package does not contain any
assembly references or content files that are compatible with that framework. For more information, contact the package author.
so I tried doing this:
Install-Package Xamarin.GooglePlayServices.Base -Version 29.0.0.1
I got the same error as I got with nuget package version 60.1142.0
I am using Visual studio 2017 enterprise version.
any help in this regards will be appreciated. Below are the target for android project:
My target framework is like this:
and The sdk Picture is like this:
Below is the visual studio Help-> about window.
Generic message:
Could not install package 'Xamarin.XXXXXXX'. You are trying to install this package into a project that targets 'MonoAndroid,Version=vX.X'
Specific message:
Could not install package 'Xamarin.GooglePlayServices.Base 60.1142.0'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v7.1'
Change your Xamarin.Androidproject to target at least MonoAndroid 8.0 as Xamarin.GooglePlayServices.Base v60.1142.0 has a dependency on 8.0
Nuget: Xamarin.GooglePlayServices.Base/60.1142.0
Dependencies

How to associate new project and already downloaded NuGet packages?

How to easily associate a new project and already downloaded NuGet packages?
An example scenario:
I created a Visual Studio solution and project, named mylib. And I installed Nuget packages, like C++ boost library. I can use the boost library right away without setting header/linker directories manually. This is very convenient.
Now I create a new project (or add an existing project) under the same solution, named executable. I also want to use the boost library in this project.
Unfortunately, there is no graphical or IDE interface to link the dependency for the new project.
The above picture shows NuGet packages are installed, but newly added project executable still don't have links.
To correct this, I have to manually modify the project (e.g., .vcxproj) XML file. I copied from mylib and pasted it to executable.
<ImportGroup Label="ExtensionTargets">
<Import Project="packages\boost.1.65.1.0\build\native\boost.targets" Condition="Exists('packages\boost.1.65.1.0\build\native\boost.targets')" />
<Import Project="packages\boost_regex-vc141.1.65.1.0\build\native\boost_regex-vc141.targets" Condition="Exists('packages\boost_regex-vc141.1.65.1.0\build\native\boost_regex-vc141.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\boost.1.65.1.0\build\native\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\boost.1.65.1.0\build\native\boost.targets'))" />
<Error Condition="!Exists('packages\boost_regex-vc141.1.65.1.0\build\native\boost_regex-vc141.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\boost_regex-vc141.1.65.1.0\build\native\boost_regex-vc141.targets'))" />
</Target>
It works then.
Or, uninstalling already downloaded NuGet packages and reinstalling them also works. But that's obviously not a good solution.
I'm wondering if there is a nice way to re-associate dependency between already downloaded NuGet packages and projects. I was unable to find such feature in the project property pages in Visual Studio 2017.
To correct this, I have to manually modify the project (e.g., .vcxproj) XML file. I copied from mylib and pasted it to executable
According to your description, that seems the package boost has not been installed properly to the project executable. So you can use the NuGet command line in the Package Manager Console:
Update-Package -reinstall
to force reinstall the package to the executable project.

NuGet package reference & version

I tried crawling through the documentation for NuGet and Visual Studio but did not find an exact answer for my question. Also am new to using NuGet.
If I have a packages.config like below:
<packages>
<package id="xxx.SomePackage" version="1.0.1" targetFramework="net452" />
</packages>
And a similar reference in my .csproj for the project:
<Reference Include="xxx.SomePackage, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\xxx.SomePackage.1.0.1\lib\net45\xxx.dll</HintPath>
<Private>True</Private>
</Reference>
Suppose I have a newer version which I want the projects to use namely 1.0.2, should I manually change each csproj/packages.config reference to point to that version or is NuGet smart enough to get and apply only the latest version to my projects ? I have a lot of projects so it's a pain to change for each one.
Note: I read about using SpecificVersion: False. Is that something I can use ?
Note: I also read about "Update-Package -reinstall". Is this the best and preferred method for scenarios like mine ?
should I manually change each csproj/packages.config reference to point to that version or is NuGet smart enough to get and apply only the latest version to my projects ? I have a lot of projects so it's a pain to change for each one.'
No, you don not need to manually change each csproj/packages.config reference to point to that version. NuGet smart enough to get and apply only the latest version to your projects.
You can use the command line Update-Package -Id <package_name> -Version 1.0.2 in the Package Manager Console, without specifying any particular project, Update-Package affects all projects in a solution. See update-package for more detail info.
Alternatively, you can also update all projects via Manager NuGet Packages for Solution. Right click your solution (not project), select Manager NuGet Packages for Solution, switch to Updates tab, choose the package you need to upgrade, then select the projects you want to update the package:
Besides, Update-Package -reinstall is used to reinstall packages, using this command is much easier than removing a package and then trying to locate the same package in the NuGet gallery with the same version. So this command would not update the version of the package.
Hope this helps.

NuGet keeps ignoring "allowedVersion"

I'm using NuGet in VS 2013 and try to limit the JQuery Package to version 1.x (instead of 2.x)
Here is what I have in my packages.conf
<package id="jQuery" version="1.11.2" targetFramework="net45" allowedVersion="[1,2)" />
Which to my knowledge tells nuget to exclude versions starting with 2
Now, when I run the following command in the console to see what would be updated.
Update-Package -ProjectName Website -WhatIf
it shows me
Updating 'jQuery' from version '1.11.2' to '2.1.3' in project 'Website'.
Remove 'jQuery 1.11.2' from project Website.
Add 'jQuery 2.1.3' to project Website.
Which is not what I expected. Why does nuget want to update to version 2.1.3 even when I said exclude this version.
Am I missing something here?
This is not working because the attribute should be allowedVersions and not allowedVersion. The following entry in the packages.config file should as you are expecting it to.
<package id="jQuery" version="1.11.2" targetFramework="net45" allowedVersions="[1,2)" />

Resources