I see a packages.config file for each of my projects in a solution. It contains info about various assemblies info. I am expecting that the NuGet will automatically scan these packages.config and download as necessary. But it didn't. Do I need to manually install all the packages?
If you right click the project in question you can select "Manage nuGet Packages" from the menu. After you do that you can click "installed packages" on the left hand side to see the packages that you currently have installed. These are what you are seeing in your "packages.config" file. If you wish to update the packages or reinstall them you can do that through the interface here by clicking "uninstall", then finding them in the list an re-installing them again.
Alternatively you can use the package manager console to do things like updating, installing older versions or all sorts of things with the nuget manager. See here for some details about that. (Information about updating a package is at the bottom of the page).
Best of luck!
Related
I want to use a nuget package as a dependency for a personal project of mine, but the contents of the package that I want to use are not included in the latest release. It is a project that only gets releases about every year or two. There was some essential code added to the Github repo of the nuget package in question recently and really want to use the new code.
Btw, I know that this isn't recommended because using bleeding edge and unfinished code is a recipe for bugs and maybe even security vulnerabilities. This is an exception though and I am using this code privately and at my own risk.
So in order to get the bleeding edge nuget code as a dependency in a personal project of mine, I cloned nuget project's repo, renamed the repo and ran dotnet pack --output nupkgs. This created a .nupkgs file and I uploaded that to my nuget profile. I made my nuget upload unlisted because, again, this is private/personal use code at my own risk and I don't want anyone else using it (and possibly running into security issues).
So back to my own personal project where I want to add this bleeding edge self uploaded nuget dependency... I ran this command dotnet add package <MY UNLISTED NUGET PACKAGE> --prerelease and I got this in my terminal:
Determining projects to restore...
Writing /var/folders/path/to/file/tmp<RAND NUM HERE>.tmp
info : X.509 certificate chain validation will use the fallback certificate bundle at '/usr/local/share/dotnet/sdk/6.0.401/trustedroots/codesignctl.pem'.
info : Adding PackageReference for package '<MY UNLISTED NUGET PACKAGE>' into project '/Users/path/to/<myproject>/<myproject>.csproj'.
info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/<MY UNLISTED NUGET PACKAGE>/index.json
error: There are no versions available for the package '<MY UNLISTED NUGET PACKAGE>'.
So how do I add my unlisted nuget package to my personal project's dependencies?
If you only need that package locally, you can copy the created nuget package to a folder of your choice and add the path to that folder to your nuget.config.
This can also be done in VisualStudio in the Options -> NuGet Package Manager -> Package Sources.
But beware this dialog is a little wonky. First click on the green plus in the top right corner and do not forget to click on update after adding the folder to the "Source" line.
A comprehensive description can be found here.
We have dozens of solutions in a repository and we're retargeting every project to net472 from net462. Currently our best bet is to open each and every solution in Visual Studio and execute the following command in the Package Manager Console.
Update-Package -Reinstall -IgnoreDependencies
As far as I'm aware, the PM console cannot be used outside Visual Studio, so this method of course is not very efficient, so what I was thinking about is using the nuget.exe tool for this. However at first glance I could not find any equivalent operation or argument set.
The documentation at this moment says the following
For all packages, delete the package folder, then run nuget install.
For a single package, delete the package folder and use nuget install
to reinstall the same one.
So based on this I tried to delete the packages folder and run nuget install for a project, so I expected it to do a re-install. However, while it installed the package indeed (to packages), it does not touch the packages.config (for retargeting).
Is anyone aware of any kind of possible way to automate this process?
How to achieve full NuGet reinstall using nuget.exe CLI?
That command cannot get what you want.
As far as I know, nuget install should be with packages.config file and it will not update the nuget framework version of packages.config file automatically.
So whenever you change the target framework version of your project, using that command will not update the target framework version of the nuget package.
So only update-package -reinstall command under Package Manager Console will update the target framework version of packages.config file.
And also Package Manager Console cannot access multiple solutions so you have to open each solution to run that command.
Although it may be possible to achieve your expectations with PowerShell scripts, but it is too complex so that it is easier to open each solution and then run the command.
As a suggestion,
1) open each solution on VS to run update-package -reinstall command.
2) And migrating from packages.config to PackageReference may be a good choice. In this case, the nuget packages will automatically adapt to the corresponding project target framework version.
Before doing this,you can make a backup of your project.
3) If these all do not meet your requirements, you could suggest a feature on our User Voice Forum to report your desire for automation. After that, you can share the link here and anyone who is interested in it will vote it so that it will get more attention from Microsoft.
Like title says, I can not build my solution(C#) as NuGet is spitting out this error
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 ..\packages\Fody.1.26.1\build\Fody.targets.
When I run Get-Package, it says no packages are installed.
How do I get rid of this(I have no need for the package anymore).
Thanks
You don't want to use the project based nuget package restore!
Make sure you have the latest Nuget version (Tools -> Extensions and Updates)
When you go to build the project it should tell you it needs to download the nuget packages (or might just auto download them).
Edit not sure whats with the downvotes:
http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html
To find the menu item: "enable nuget package restore" right-click in the solution explorer on the solution - not on the project.
You get a message:
Do you want to configure this solution to download and
restore missing NuGet packages during build?
Press Ctrl+Q then type "Package Manager Console", This will bring up a console like interface.
Type in
Uninstall-Package Fody
and press enter will remove this package for you
So i created a new solution. Added all my projects to it. Downloaded all the nuget packages.
I checked it all in. On another pc I pulled the solution down. I hit build and I get a tonne of errors relating to not being able to find the dll of the packages.
So I set automatically download packages if they're missing. Still nothing works. Why is this?
When I Enabled it, it came back with an error saying that it could not modify the projects because they were locked.... This is why I want to re-enable the context menu item that allows me to enable nuget to automatically download missing packages.
I think the problem is I checked in all the packages. They all got download onto the other machine, that's why NuGet was saying that I already had the packages.
I solved this by going into the solution directory (physical path) and deleted the packages folder.
Then I built the project, and true to NuGets word it downloaded all the packages again. It also succeeded in building the application, no errors!
I would advise that if you are going to enable the NuGet package restore that you check out the solution first, once you're done check in the solution!
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