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

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".

Related

Difference in nugets processing via `dotnet add package ..` vs nugets adding via visual studio UI

I need to use native c libraries in my library(that supports several Core TFs and .net framework) which is published via nuget. I configured it via .csproj file and runtimes folder. But I noticed that when I consume my NuGet via dotnet add package .. in some cases, the native libraries are not copied into the expected folder after consuming, however when I use the VS UI Nuget package manager->Manage Nuget Packages for Solution, all files are placed into correct places.
So, I assume that Nuget package manager makes more steps than just call dotnet add package .., but it's unclear what exactly happens, any help will be appreciated.
Actually, dotnet add package does the same effect as Nuget package manager UI in VS IDE. They simply install a Nuget package into your project and there is no difference. No additional operations will be performed. Like add some xml node in
So I think there is something else wrong in your project.
Please check under tips to troubleshoot your issue:
1) clean nuget caches first or just delete all cache files under C:\Users\xxx(current user)\.nuget\packages.
2) And if the runtimes folder does not exist under your project, I think it is controlled by dependency assets. Like ExcludeAssets=runtime or native. It will prevent the function of runtimes folder. Please see this official document.
So after you finishing installing the nuget package, you should check your csproj file, and make sure that there is no such like
<ExcludeAssets>runtime;native</ExcludeAssets>
under PackageReference node.
If there is any this node, please delete it.
3) delete bin and obj folder. Then rebuild your project to test again. Or if you use dotnet command line, you should additionally add dotnet build command. In my side, I run dotnet build -p:platform=xxx;Configuration=Release.

Updating solution level nuget packages in visual studio

I'm trying to figure out a) if I'm going about this in the right way and b) how to update a solution level nuget package.
The core problem is that when a package is installed at the solution level (rather than in any particular project) and you try to update it, it doesn't remove the old reference. It just adds a new package reference, and imports both version. Which typically means (what with how powershell modules work) that the earlier powershell modules override the newer ones.
So what I have to do is uninstall the package and re-install it, which grabs the newer version. Seems inefficient.
Also, I can't seem to install or uninstall a solution level package from console. I have to do it with the Manage Nuget Packages utility, which I hate to use.
Here is some background on what I'm doing, if it helps:
I've set up a system at our company of using solution level nuget packages to add custom powershell script modules to the solution, as well as some more generalized scripted solutions I've written (like deleting TFS work items or changing a project name on the file system as well as within code).
So one project might have the DataServiceUtilities package and another would have the FrontEndUtilities package.
So, how can I update these packages without it adding two references? And can solution level operations be done in the Package Manager Console, which always defaults to targeting a project?
It appears that some of this comes from bugs in the Package Manager GUI tools, and Nuget in general
The Package Manager GUI tool doesn't handle updates properly for solution level packages. But if you run Update-Package from the package manager console it will correctly uninstall/re-install the solution-level package.
As for installing from command line, if a package has only a tools folder and no dependencies you can run install from command line and it sill install in the solution and ignore the default project.
However, as of now (Nuget 2.8) Nuget has a bug in it that causes it to treat solution-level packages with dependencies on other solution-level packages as project-level packages. It's apparently been in for about a year, and they claim it will be fixed in VS 2015. You can see the bug here: https://nuget.codeplex.com/workitem/3642
What this means is you cannot currently create a solution-level package with ANY dependencies. Please note that this is legal according to the documentation. Hopefully it will be fixed next year.
*Update
Just a quick update. It appears that in VS 2015 they have deprecated (or, more accurately, removed) solution level/tools only packages. After some out outcry they also decided to re-implement them in a future version, but it may be awhile before they do so.
Progress on re-implementing the feature can be found here: https://github.com/NuGet/Home/issues/1521
Discussion on how to work around the missing feature can be found here: https://github.com/NuGet/Home/issues/522

How to trigger NuGet v2.x Package Restore from CruiseControl.Net

Is it possible to trigger a NuGet v2.x package restore when trying to build a VS2010 solution using CruiseControl.Net?
We've recently set up CCNET and are simply trying to trigger a test build of our main solution. Many projects within the main solution have NuGet package restore enabled. The packages folder is not committed to our VCS. Because of the new "feature" of having to consent to the package restore in Visual Studio, MSBuild is failing when it hits the restore package target in the nuget.targets file.
If it is possible without drastic changes to every project that uses NuGet or to write a custom build script, what is the best way to accomplish the package restore?
from http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages
To enable package restore for build servers without Visual Studio installed, you can also set the environment variable EnableNuGetPackageRestore to "true".

NuGet package restore consent without NuGet

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.

How do I integrate NuGet into my Bamboo Build Plan?

Our build plans for Sitecore (.Net) websites are currently using Bamboo as the build plan master for continuous integration process. Bamboo supports building a .Net project, and that .Net project contains references to several Sitecore binaries.
I have used NuGet as an artifact repository, mostly because that seemed to be the one most people were using.
So, now that I have a nuget repository, am hosting my own feed, and have added the Nuget package to my project (I just installed the package of binaries I created), what more do I need to do?
Should the build call out something special, or am I done? I guess I'm just nervous that bamboo isn't talking directly to my repository....
In the closest analogy I have, namely a Maven/Archiva combo, the maven plan specifically references the artifacts in archiva, pulling the correct version as needed. Does NuGet do this?
Since there have been some new developments in the NuGet package restore approach, I thought I'd post an update on this topic. We're using Visual Studio 2012. I wanted to be able to run MSBuild and make sure that it would first restore NuGet packages without setting "Package restore" to true in the config. Here's what I did (inspired by https://stackoverflow.com/a/23935892/414376):
Upgraded NuGet in my solution to a version later than 2.7 (2.8.3 in my case; this seems like an optional step)
Installed NuGet.exe on the build server
Added NuGet.exe to my remote agent so that it could be run as a command from Bamboo
Added the NuGet command to my build plan with argument restore (so that the command will be nuget restore); I've placed it right before my MSV Build task.
That was all I needed to get this to work properly according to the latest guidelines.
Nuget 1.4+ supports "Package restore" which embeds a call to an MsBuild task in the project file. When the packages are not available it will automatically restore them while building the project.
I'm sure this is old news, but my packages are in \packages. No amount of "dotnet restore" would work, until I explicitly mentioned the packages folder.
dotnet restore --packages .\packages
restored them!
VS2019. just in case it's version specific.

Resources