Force re-download of solution and project NuGet packages without reinstall - visual-studio

Is there a way via NuGet.exe or within Visual Studio 2022, natively or via the Package Management Console, to only re-download all packages for a given solution and/or project without re-installing them?
This may sound odd, but we occasionally run into a scenario where our packages path mappings get wonky, and we correct the paths in the .csproj files and whatnot, but Visual Studio believes that the packages are installed due to their listing in the packages.config, yet in our mapped packages path, they are not downloaded.
We do not want to reinstall, as for many projects, that uninstalls and reinstalls the packages, causing unwanted changes to the code, as default templates and other things get changed.
We simply want to say "Hey Visual Studio, you see all these packages that you think are downloaded and installed in C:\NuGetPackages...? Yeah, they are not there. Please just download them. Don't reinstall them please."
Any way to do this in 2022 yet?

Only re-download all packages … without re-installing them.
If you only downloading the NuGet packages, they are just .nupkg files. If you download and install them, you will get some files like .dll files, .nupkg files, .xml files and so on. If you download and install them, then reference them in your project(such as installing them into your project by using VS or configuring in packages.config file), your project will connect to these NuGet packages.
The third situation obviously doesn’t meet your requirements, so just focus on the first and the second situation. For only downloading the NuGet packages, I don’t find many good methods. Maybe manually or writing some scripts to download them from nuget.org? But you want to use VS or NuGet.exe, so not possible I think.
For downloading and installing NuGet packages, or installing them to a specific folder for preparation. You may try and modify following command(nuget.exe, install command):
nuget install <packageID> -version X.XX.X -OutputDirectory c:\XXXX
BTW, based on my check, there’s no options in VS 2022 to only downloading the NuGet packages without installing them. And for above situations, perhaps some third-party tools will work.

Related

Why doesn't Visual Studio notice changes to packages.config on build?

I'm not very familiar with Nuget, especially against VC++. I realised I needed to add Curl to my executable simply because it links a library using Curl.
So I edited the .exe's package.config:
<package id="Curl" version="7.59.0.0" targetFramework="native" />
<package id="Curl.redist" version="7.59.0.0" targetFramework="native" />
But again I am having to jump into the Nuget console in VS to update/restore things first. Why isn't this happening automatically? Is it possible to make it work that way?
Worse still, running update-package tells me there are no updates required. I have to reinstall them every time.
Why isn't this happening automatically? Is it possible to make it work
that way?
As zivkan said, it's not a valid workflow to manually edit packages.config so it's not happening automatically. And if you have to consume nuget packages in this way by manually adding and editing packages.config file, you can right-click the solution in solution explorer and click Restore Nuget Packages to restore packages first.
running update-package tells me there are no updates required
For Curl, in Nuget Gallery there's only 7.30.0.2(latest) version which depends on Curl.redist-7.30.0.2 version. I'm not sure where you can find the 7.59.0 version (It seems it has been released,see here), but it's obviously not published to nuget.org. So when you try to restore nuget packages from available nuget source in nuget console or Solution's Restore Nuget packages option mentioned above, you'll get no updates required or error like unable to find version 7.59.0 of package curl.
To resolve this issue, you can go Tools menu=>Nuget Package Manager=>Package Manager Settings=>Package Sources to configure the source where to find the 7.59.0 version of Curl. Then you can use the Restore nuget packages option to restore them easily for all projects in the solution. Or you can just trying changing the version 7.59.0.0 to the 7.30.0.2 which is exactly available in nuget.org.

Confusion over NuGet in Visual Studio

Our VS2013 solutions contain a solution folder called .nuget, containing the files NuGet.config, NuGet.exe, NuGet.targets. What is the significance of this folder and what uses the files? Is it related to the "enable package restore" feature?
If I install or update a package (via the "Manage NuGet Packages" UI or package manager console), does this involve running the above NuGet.exe, or something else? VS is telling me that the NuGet Package Manager is up to date (via the Extensions and Updates dialog), however the above NuGet.exe is quite old. I've also found a very old NuGet.exe file in C:\Program Files (x86)\NuGet\. What uses the latter, and what are the implications of these exes being out of date?
The reason I ask is that we've been having problems with a couple of solutions over recent weeks. We can't update NuGet packages - the operation fails with the message "Error: An item with the same key has already been added". I'm trying to track down the cause, and wondering if these out of date NuGet.exe files might have something to do with it.
As far as I remember this folder is useless now with the latest nuget extension to Visual Studio. It was used before and was nothing but pain in the ass. I am not 100% sure about 2013, but in 2015 all works fine without it, so my suggestion is to update to the latest available nuget extension version and try to delete the folder, most likely everything will work.
Now packages go to current user folder, and use the config from %AppData%\NuGet\NuGet.config. For NuGet 2.6 or earlier, this setting was available in a project-specific .nuget\nuget.config file.
You can read more about it here.
So nuget is gradually getting better and easy to use without too much thinking of all this "magic" folders and stuff.

Visual Studio + nuget + TFS: checking in nuget packages?

I'm working on a TFS project with a small team. This project has a bunch of nuget packages installed, but it's for a 4.0 project, and the nuget package manager GUI doesn't even offer the older versions of the packages any longer since their 4.5 equivalents are now being used. In order to allow other team members to compile the project, they need to have the exact versions of the packages. I'd like to check in the entire "packages" folder used by nuget. Is this a good idea? If so, how does one check in the "packages" folder and all its contents since it exists at the solution level? There is no "Include in Solution" option in Visual Studio as there is when you right-click an assembly.
in the past I have also checked in the NuGet packages into version control. With this some problems appeared:
Some packages where not checked into version control when committing from Visual Studio into TFS.
Updating packages became a real problem.
For the first problem I had used the TFS Power Tools. The problem with this solution is that every developer needed to install the Power Tools.
A better solution came up with NuGet 2.7. It introduced package restore. With package restore there's no need to check-in the packages folder. They will be restored during build.
We use an on-prem TFS install with no internet access so we have to check in our package folders or our builds fail. The biggest issue is that VS does not behave consistently when it comes to adding the pending changes for new package files, often times it will ignore the .dll files in the pending changes window, sometimes it adds everything fine.

Creating a vs.net 2013 solution with multiple projects, nuget is causing real problems

When other developers get the vs.net 2013 solution from TFS, Nuget doesn't seem to work as expected and many of the individual projects in the solution do not have the required dll's downloaded (although they are defined in the packages.config file).
If I go to view the installed packages, it shows up as they are installed and the correct projects are selected.
I went into console and ran:
Update-Package -Reinstall
After doing this, my packages.config file was truncated for whatever reason and 80% of my packages were removed from the config file!
What should I be looking into as it is either I have setup the solution incorrectly or nuget just isn't reliable.
Thoughts?
First of all make sure that NuGet Packages Restore is turned ON.
This forces to restore missing binaries directly from NuGet server. You can right click on Solution and enable this option as follow:
Make sure that .nuget folder that contains nuget.exe is created under your Solution.
You'll want to make sure that you have automatic package restore turned on in VS 2013. You can do this in the options.
Then, when you build, VS should grab the packages for you. If you want to manually restore the packages or do it from powershell, you'll want to use the command nuget.exe restore in the folder your solution lives in.
If you're using custom package sources, you'll want to make sure you specified them in your nuget.config file.

Do Nuget packages need to be added by every developer who works on same VS project?

I've added some libraries to a VS 2010 solution using Nuget (RestSharp, Twilio, etc.). When I pull the same solution down to a new PC from TFS and try to build it, all the references to those assemblies are broken (error "namespace cannot be found..."). Is it necessary for each developer who works on this VS solution for the first time to independently install the same Nuget packages on their PCs?
Thanks,
Jim
As Andrew already have said it's all about the packages' location.
Either you have to check in the entire packages folder with all the packages, or each developer have to install the packages after first checking out. But there is a better way to do this, namely to use NuGet Package Restore - which will automatically install all missing packages when the project is built.
If you use package restore, you only need to check in the repositories.config into your VCS. With TFS you can cloak the entire packages folder except for the repositories.config, so that TFS doesn't annoy with pending checkins for new packages.
Also see this answer for guidance on how to use TFS + NuGet.
No, but you need to be sure the assemblies are all included in the same relative path so Visual Studio can find them. You can include the solution's nuget packages directories, which is where I think it stores a copy of the libraries to be referenced by the project(s).
Incidentally, including said diretories may be effectively the same as "installing the packages". If you include all the files that NuGet uses in its management of packages, NuGet will behave the same as if you had installed them. But you don't need to do the actual package install via NuGet for it to work... or even have NuGet installed in Visual Studio in the first place. It's just a matter of the proper files being where the Visual Studio project files expect them to be.

Resources