NuGet package restore consent without NuGet - visual-studio

We recently added a few dependencies to our project using NuGet. To keep the binaries out of the version control system, I enabled the package restore feature and added the resulting .nuget folder to the repository. Also the project with the dependencies got the RestorePackages option set to true, and an Import-tag for the nuget.targets within the .nuget folder.
So that all works well on my machine with NuGet installed and the package restore feature enabled in my VS settings. However when I want to use this setup to install the dependencies on other machines I run into a few problems.
I was under the impression that one advantage of including the nuget.exe would allow me to use this on machines that do not necessarily have NuGet installed. However, after reading the article on consent I think the reason it actually fails is that those machines do not have the package restore feature enabled in their settings – obviously as they technically do not even know about NuGet.
What is the preferred way to enable package restore on machines that do not have NuGet installed? Is not having NuGet installed actually a valid option other than for build servers?
Or ideally, is there a way to enable package restore by default from the solution if NuGet isn’t installed itself and as such the setting could not be set by the user? (I actually could think of a setup-script that creates a NuGet.Config to %AppData&\NuGet)

Try this:
Install-Package NuGetEnablePackageRestore
Or check the contents of the package (unzip it), you'll find some interesting stuff there that will help you out (e.g. there's a way to set an environment variable from within MSBuild). You can download the package within the browser after logging into NuGet.

"Or ideally, is there a way to enable package restore by default from the solution if NuGet isn’t installed itself and as such the setting could not be set by the user?"
The alternative to install NuGet and enabling consent through the Settings is to set the following environment variable :
set EnableNuGetPackageRestore=true

If EnableNuGetPackageRestore (mentioned by Alexandre Dion) variable used as emmited Property for Msbuild script (I strongly suspect it work this way, but cant check right now) - you can tune up your projects or sln to set this additional property to true.
Anyway, according to this you should have at least nuget.exe as console manager for each dev. Otherwise you cant fetch referenced nuget packages.

Related

This project references NuGet packages that are missing on this computer (TFS)

I'm using TFS for the first time and attempting a build. I'm getting the error:
This project references NuGet package(s) that are missing on this computer. use NuGet Package Restore to download them.
I realize that there are many similar posts on StackOverflow and I've searched through quite a few of them. What I've gathered is that the two boxes under Package Restore in Package Manager Settings should be checked (but that this is also irrelevant now because they're checked by default). I verified that mine were both checked anyway.
The next piece of advice I considered is deleting the /packages folder from the Source Control version of my application. There is no packages folder there OR in my local (pre migration to TFS) version of the application. Instead, there's a ../packages/ folder (up one level) from the application folder. It seems that, at some point, I've opted to store the packages for all of my applications in the same folder? If so, where is this setting and what do I need to change it to either in my local version or in Source Control Explorer?
Thanks!

Can NuGet package manager install updates automatically? (For Test Automation)

As per the title, I want to know if it's possible to set NuGet Package Manager to install any package updates automatically.
I've looked for and found an answer to this on here but it's not specific enough to my situation, I don't think (Question: Is there a way to automatically update an installed NuGet package in Visual Studio?). My code is for automated tests rather than anything that would be released on a regular basis. The only time we'd change any of the code would be to add or amend existing tests.
I'm quite early on in my automated testing career so any advice would be greatly appreciated.
Thanks,
Sheridan
I want to know if it's possible to set NuGet Package Manager to install any package updates automatically.
There is no such option can be set directly to NuGet Package Manager to install nuget package updates automatically. But you could add a simple command in the pre-build event to achieve it, like:
nuget.exe update "$(ProjectDir)packages.config"
With this pre-build event, VS/MSBuild will update all installed packages in your project when you build your project.
Note:
Since nuget.exe is not a windows internal command, so you should add nuget.exe to the system environment variables, otherwise you should specify the full path of nuget.exe, like:
"C:\Users\<uasername>\nuget.exe" update "$(ProjectDir)packages.config".

Howto disable nuget machine-wide cache?

As you know NuGet uses %LOCALAPPDATA%\NuGet\Cache location for caching. It first checks if requested packages is here then download if needed.
How can I properly disable this cache mechanism from Nuget and "Visual Studio 2013", and make sure they always download from sources?
Can I build Nuget Package Manager Extension from source, then install it to Visual Studio? Or Are there any registry configuration that disable it?
Thanks
You cannot disable NuGet from using a cache. The only thing you can do without changing the source code is to change the location of the cache directory using a NuGetCachePath environment variable.
So you are left with clearing the local cache manually or automatically before installing a NuGet package or modifying the source code for NuGet's Visual Studio extension.
The source code for NuGet 2.8.5 and older is available on CodePlex.
The source code for NuGet 3.0 is available on GitHub
There are some instructions available on how to setup the NuGet development environment to be able to build and run NuGet within Visual Studio.
Currently it's possible to do so in case you'd running Install NuGet packages task through CLI which is common practice.
You can order NuGet to not use it's cache at all by using -NoCache input parameter. Then it will behave as you described. See CLI reference of NuGet.exe

Nuget Packages.config change - does not force csproj update

I've got problem with version of dependency that I set manually.
Note: I use Automatic restore within Visual Studio.
When I set Version="1.3.12.5" for my dependency in packages.config I expect that restore will install package and it will be referenced in next build I trigger. But it is not true. Package is installed and placed in packages directory but build does not use this downloaded packages (as csproj is not changed automatically).
Do you know possible scenarios to workaround this problem?
I tried to use Proget Client Tools but it turned out that it is not possible to use local directory feed with this. I need local and remote feeds support also, so it is additional requirement.
So, paraphrasing my question is...
How to easily change referenced version of package without touching csproj? (which is hard to edit in visual studio) Editing version twice (one in packages.config, two in csproj) is also an overkill.
Remember Package Restore simply downloads the package to the packages folder. It does not update project references as NuGet expects that the package had previously been installed. It's simply downloading the missing package files.
Package Restore is not a replacement for Install-Package. You can specify a specific version when installing. This will add the project references properly.

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.

Resources