cannot install NuGet package into project - c#

I cannot install the NuGet package System.IdentityModel.Tokens.Jwt (.Net JWT Handler) into my project. If i try to install the package with NuGet, it will install into the root of the solution only (a .nuget folder is created in the root of the solution). I need to install the package in my project, not the solution.
Why would this happen? I tried passing in the project name to the Install-Package command in the Package Manager Console, and that looks like it installs correctly but no references are added to my project and the packages.config file is not updated.
My project is currently referencing .Net 4.5.1 and I have also tried with .Net 4.5.
The package I am trying to install is here:
System.IdentityModel.Tokens.Jwt

I'm having the same issue. I was trying to install the package as said in this article http://msdn.microsoft.com/en-us/library/dn205064(v=vs.110).aspx
So, I look into the package history and finally I installed the previous package
http://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/3.0.0
It works fine for me.

With NuGet, you can now specify the directory the packages are installed in.
http://docs.nuget.org/docs/release-notes/nuget-2.1
Specify ‘packages’ Folder Location
In the past, NuGet has managed a solution’s packages from a known ‘packages’ folder found beneath the solution root directory. For development teams that have many different solutions which have NuGet packages installed, this can result in the same package being installed in many different places on the file system. NuGet 2.1 provides more granular control over the location of the packages folder via the ‘repositoryPath’ element in the NuGet.config file. Building on the previous example of hierarchical nuget.config support, assume that we wish to have all projects under C:\myteam\ share the same packages folder. To accomplish this, simply add the following entry to C:\myteam\nuget.config.

The package System.IdentityModel.Tokens.Jwt 3.0.1 has some problems: the file System.IdentityModel.Tokens.Jwt.dll and System.IdentityModel.Tokens.Jwt.Xml should be put in directory lib\net45, but they are put in the root directory instead. This causes NuGet to think the package is a solution level package, and will not install the package into a project.
This problem was fixed in System.IdentityModel.Tokens.Jwt 3.0.2

Related

Installing NuGet package in the root directory

I've created a NuGet package which should not be installed to a particular project but rather to the root directory of the solution.
The installation works fine via command line. I'm wondering why a packages.config is not added to the root directory on installation? The problem is that if I run: nuget list -Source "MySourceName" is displays No packages found.. Here is the problem that an uöpdate of the package would not be possible. What is the best approach in this scenario?

.NET Same version nuget package to two projects in one solution

We have a solution with two projects (both version .net 4.6.2).
When installing a nuget package from our private Nuget Feed to either one of the projects, it works.
If we try to install the same package version into both projects, then package gets installed into one of them, and the other one gives error : "Error Could not install package 'OurInternalPackageName 1.0.1.5'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.2', 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. ".
We tried installing nuget using 'Manage packages for solution' option, manage nuget packages for projects separately but the result is still the same.
Changing .NET framework versions does not help.
Clearing Nuget cache did not help as well.
The workaround we are using now: install package to one of the projects, and then install a lower version of a package to another project.
We tested this with 'Automapper' Nuget, tried to install into both projects and it worked (Same version got installed into both projects).
Any ideas would be appreciated.

How do I update UWP projects' nuget packages via the CLI?

All .NET framework projects that use Nuget have a packages.config per project. When I run something like:
nuget update MySolution.sln -Id PackageName -Version 1.2.3
It will update all projects in my solution that use this package to the specified version (1.2.3 in this case)
However, I'm finding that this does NOT work for UWP projects. UWP does not use packages.config and instead put the package references directly into the csproj file. As a result, this is literally what nuget update says when I run it:
Found 2 projects with a packages.config file. (A.csproj, B.csproj)
where A and B are my .NET Framework projects that still have a packages.config file. But this list doesn't include my new UWP projects.
Is there another command for nuget update that will work with UWP projects?
How do I update UWP projects' nuget packages via the CLI?
This is a known issue for the packagereference. At the moment, NuGet CLI does not support automatic package updates to the the new .NET Core .csproj format, you can refer to the below GitHub issue for details:
support for updating references into csproj from commandline(s)
Besides, as test, the workaround using following command line does not work with UWP project
dotnet add package <PackageName> --version <version>
Indeed, currently it is very inconvenient to manage packages outside of Visual Studio for UWP with packagereference.
Hope this helps.

When added to solution NuGet packages restore/install to multiple locations

I'm using Visual Studio 2017, building a .Net framework (not core) v4.6.1 ASP.Net MVC project and when I added packages to my single project inside my solution the packages are seemingly restoring/installing to multiple different locations. I am installing packages from multiple feeds, some are internal to my company and others are public.
Some packages are located at my solution root and others seemingly are landing at %userprofile%.nuget\packages\
One package even installed and its hintpath was in a completely different location from the two of them. The package was installed there but I don't know why it didn't install to what I consider the solution's local package folder.
I'm not sure if these are the right questions to ask yet, but these are what I'm trying to answer for now:
For VS2017, .Net framework, ASP.Net MVC what is the default package install location?
How do I specify which feed a package comes from for CI/CD purposes?
Does NuGet look for packages already installed on my computer?
If yes, where does NuGet look for packages and where can I find its list of locations it looks for.
Thanks!
1.For VS2017, .Net framework, ASP.Net MVC what is the default package install location?
It depends on which package management method you using. If you are use package.config, the default package install location is solution root, if you are use PackageReference, the default package install location is %userprofile%.nuget\packages\. That is the reason why you added packages to single project inside the solution the packages are seemingly restoring/installing to multiple different locations. You can unload and edit your project, check the project file .csproj, you will find following:
<ItemGroup>
<PackageReference Include="xxxxx">
<Version>x.x.x</Version>
</PackageReference>
</ItemGroup>
To resolve this issue, you can accept the advice of Lex. If you want to unify, make the choice and change the files. You can uninstall those packages which using PackageReference(or package.config), then change the nuget settings(Tools->Options->NuGet Package Manager->General->Default package management format->Packages.config), then reinstall those packages, make sure they use a uniform form.
2.How do I specify which feed a package comes from for CI/CD purposes?
You can not do such things and you do not need to do things. As we know, when we install nuget packages from multiple feeds, all the packages are downloaded to the local host, Visual Studio will use those packages on the local, Nuget does not care which feed it comes from.
3.Does NuGet look for packages already installed on my computer?
4.If yes, where does NuGet look for packages and where can I find its list of locations it looks for.
Yes, you can use the command line nuget locals all -list to find its list of locations.
See Managing the global packages, cache, and temp folders for some more details.
Hope this helps.

How to add a nuget package to the package.config the proper way?

For my C# project I am maintaining a packages.config which includes all the dependencies my project requires. Over the time I have been copy-pasting the entries manually using a regular text editor, checking in the version number I found on the NuGet website and so on. To restore the package upon a checkout, I use nuget -o nuget-packages install packages.config which worked good so far (I am using Xamarin Studio on non-windows systems, so no VS available).
I was just realizing that messing with the packages.config in a text editor couldn't be the intended way. I know from npm and bower that a npm install --save-dev <pkg-xy> will to the job and write the package version back to the config. Is there an equivalent of this in NuGet.exe?
From the command line this not supported. You will have to edit the packages.config file manually, or write a utility to do this work for you, or extend NuGet.exe with this feature.
There is no equivalent in NuGet to NPM's npm install -save
Currently the only way to have the packages.config file automatically updated when you want to install a new NuGet package to your project is to use an IDE, such as Visual Studio or Xamarin Studio, and actually install the package. Using NuGet.exe from the command line does not have an option to add/remove entries in to/from the packages.config file when installing a new package.
NuGet.exe does have an update command which will update the package to the latest version. Whilst this would update your packages.config file it also updates your project file by adding any assembly references that the NuGet package needs.
You really shouldn't be editing packages.config. Package Restore doesn't do what you think it does. It simply downloads any missing packages that are listed in packages.config.
You might think this is what you want, but Package Restore does NOT add references to your project. It also doesn't do any of the other things the package creator had intended like running an install.ps1 script.
When installing a package, NuGet handles all of this, so your project files have added references, content, etc. This and the packages.config file is what you would commit to source control. You can leave out the actual packages folder, so you don't have to commit large binary files.
When you open the solution and build, NuGet will see that the packages are missing and will download them as if you had checked them in. The actual "install" was already done (and committed). That is all that Package Restore does: no more, no less.
If you are using Xamarin Studio, you can install NuGet by following the instructions here:
https://github.com/mrward/monodevelop-nuget-addin

Categories