Nuget Package Downloads But Isn't Installed On TFS Build - nuget

Title pretty much says it all. I have a project which uses some nuget packages. All are downloaded but two of them (HTMLAgilityPack and Newtonsoft) are never installed i.e. the .nupkg file is not extracted, thus, the required .dlls cannot be found and the build fails. Here's the part of the build log file showing when the packages are restored on the build server:
Target "RestorePackages: (TargetId:587)" in file "##\nuget.targets" from
project "##.csproj" (target "ResolveReferences" depends on it):
Task "Exec" skipped, due to false condition;
Task "Exec" (TaskId:360) Task Parameter:Command="##\nuget.exe" install
"##\packages.config"
-source "https://nuget.org/api/v2/" -RequireConsent -solutionDir
"##\Sources\" (TaskId:360) Task
Parameter:LogStandardErrorAsError=True (TaskId:360) "##\nuget.exe" install
"##\packages.config"
-source "https://nuget.org/api/v2/" -RequireConsent -solutionDir
"##\Sources\ " (TaskId:360)
Successfully installed '###.Utilities.Excel 1.0.0.0'. (TaskId:360)
Successfully installed '###.Utilities.FileIO 1.0.0.1'. (TaskId:360)
Successfully installed '###.Utilities.String 1.0.0.0'. (TaskId:360)
All packages listed in packages.config are already installed.
(TaskId:360) Done executing
task "Exec". (TaskId:360) Done building target "RestorePackages" in
project "##.csproj".: (TargetId:587)
As you can see, HTMLAgilityPack and Newtonsoft are not installed as part of the RestorePackages task. Why would TFS build download but not install these packages?

As you wrote, an old nuget.exe will do this.
What I do is take the "..nuget\nuget.exe" out of the equation.
I put nuget.exe on the build server.
I store them like this:
C:\MyProgFiles\NuGet\2.8.6\nuget.exe
C:\MyProgFiles\NuGet\3.3.0\nuget.exe
You might ask why I keep the olders. There are occasionally issues with the newest build.
Then on my builds, I setup the build server, I essentially run this:
"C:\MyProgFiles\NuGet\3.3.0\nuget.exe" restore c:\builds\1\SomeDirectory\MySolution.sln -NoCache
Obviously, you'll use macros instead of hard coded paths.
This will (obviously) restore the packages.
I use "NoCache" because occasionally our private nuget cache has things removed......which are cached on the build server. The nocache arg will find this issue sooner than later.

If anyone else comes across this it could be that the nuget.exe you're using to restore the packages is outdated. In my case the project I was working on was started by someone else 2 years ago, I added a relatively new nuget package and the old nuget.exe wasn't compatible with it. You can download the latest version of the nuget.exe here
.

Related

Error APPX3217 SDK folder containing 'UAP.props' for 'UAP 10.0.20348.0' cannot be located, even after installing 10.0.20348.0 with choco

I have an ADO build that keeps failing with,
Error APPX3217: SDK folder containing 'UAP.props' for 'UAP 10.0.20348.0' cannot be located.
That helped me locate the missing 2104 SDK. Earlier in the build, I attempt to remedy this with chocolatey by installing a 2104 SDK, which as far as I can tell is the only 2104 option available with choco:
- task: CmdLine#2
inputs:
script: 'choco install windows-sdk-10-version-2104-all -y'
It installs fine. The build breaks at the same point on multiple re-runs across multiple build nodes. All the similar questions I've run across with the same kind of error seems to automatically resolve after installing the correct SDK.
I wasn't sure if it would help, but I also installed the Microsoft.Windows.SDK.BuildTools NuGet package for the faulting project, and it also did not resolve the issue.
I've also tried both the MSBuild and VSBuild tasks. Any idea why it may not be detecting the installation at build-time?

Microsoft NuGet targets Error while building Project from Teamcity

I attempted in building the .NET Standard Library Project using .NET Framework 4.6.1 from Command prompt using MSBuild Commmand. I manage to succeed building the project from command prompt.
I tried the same MSBuild command to build the project from Teamcity Command line build step, but ended up getting the following error:
C:\Program Files (x86)\MSBuild\Microsoft\NuGet\Microsoft.NuGet.targets(140,5): error : The package Microsoft.NETCore.Portable.Compatibility
with version 1.0.1 could not be found in C:\Windows\system32\config\systemprofile\.nuget\packages\. Run a NuGet package restore to download the package.
I tried Restoring nuget.exe restore mysolution.sln but noting works.
Please help me to compile the solution from Teamcity command line step. Its strange to get compiled from command prompt but not from teamcity command line.
Looks like there is a known issue in NuGet when restoring packages using the LocalSystem account wherein the packages cannot be accessed under the C:\Windows\system32\config\systemprofile\.nuget\packages folder, even though account permissions should allow it (see this GH issue). The current recommended workaround is to use the NUGET_PACKAGES environment variable to specify another location for the packages (e.g. C:\NuGet\packages).

How to run Nuget update in TFS 2013 script

I'd like to have my TFS 2103 build update some of the NuGet packages in the project to their latest versions before the build.
I've written a pre-build script to do this by invoking the nugget.exe update command:
& .\.nuget\nuget update ".\XXX.Main.Web\XXX.Main.Web.csproj" -Source Initial -Safe -Id XXX.Feature.Test -Verbosity detailed
The log file contains:
Looking for installed packages in 'packages'. Updating
'XXX.Main.Web'... NuGet.CommandLineException: Unable to find
'XXX.Feature.Test'. Make sure they are specified in packages.config.
I've tried running the command manually on the build server from the command prompt and it works as I would expect. I've also checked that script is being run from the correct folder.
The package certainly exists in Packages.config.
Has anyone managed to get nugget.exe update working successfully within a TFS powershell script?
After much head scratching I've found that the pre-build script is run pre fetching the packages from NuGet. Running the powershell script manually after the build had completed was fine as the packages has subsequently downloaded.
The NuGet message is somewhat misleading.
My solution is to run a NuGet.exe restore command prior to runing the update command and everything now works.

How to use paket from command line

I installed paket from nuget in Nuget Package Manager Console with:
Install-Package paket
I then tried to run paket convert-from-nuget. It stalled out on a user prompt (it wouldn't let me type into the package manager console). My next thought was to run it from command line, but how to do so is not documented.
Just putting paket convert-from-nuget into a standard dev command prompt results in an error saying "paket" is not recognized.
How do I run paket from the command line or powershell, and how do you specify which solution to work against?
The way to setup paket in your repository is as follow:
1 Download a release of paket.bootstrapper.exe
This is a lightweight utility which obtains and updates paket.exe, pick stable release from official release page:
https://github.com/fsprojects/Paket/releases
2 create a .paket folder
md .paket
3 put the downloaded bootstrapper in this folder and invoke it
cd .paket
paket.bootstrapper
now you have an up-to-date paket.exe ready to ease your handling of dependencies.
4 convert from nuget
cd ..
.paket\paket convert-from-nuget
Please checkout the https://github.com/fsprojects/Paket.VisualStudio also for Visual Studio plugin to help you authoring paket.dependencies and paket.references file
Please also join https://gitter.im/fsprojects/Paket if you have any questions.
The Chocolatey package modifies the PSModulePath envivornment variable. I've observed that sometimes that modification isn't picked up until the system is restarted (or at least not until the user logs out and back in again). In the meantime, you can import the module using:
Import-Module <path-to-packages>\Paket.PowerShell\Paket.PowerShell.psd1
The packages path is usually something like C:\Chocolatey\lib. OTOH, re-reading your question, are you referring to the Nuget inside of Visual Studio? If so, that downloads from NuGet.org and that pkg puts paket.exe in $(SolutionDir)\packages\Pakget.1.18.5\tools\paket.exe. Your version number may varying.
Unfortunately the fact that PowerShell V5 introduces Install-Package (which downloads from Chocolatey by default) is going to get a little confusing vis-a-vie the NuGet Package Manager Console's Install-Package in Visual Studio.

nuget restore fails on build but works manually

VS 2013 fails to restore a package - the package contents are not materialized - although VS/nuget appears to think that it did restore the package successfully.
If I manually uninstall and re-install the same version of that package, it works as it should.
A bare-bones repro can be downloaded as a zip. This repro has a
single solution with a
single project with a
single file, "packages.config", specifying a
single package, "breeze.edmbuilder -version 1.0.4", containing a single file, edmbuilder.cs
single folder, "App_Start", contains nothing but
the .csproj says it should have "edmbuilder.cs" which is ok because
it WILL have "edmbuilder.cs" when the package is restored.
When I build, VS reports that "edmbuilder.cs" is missing ... and indeed it is missing.
However, the package was downloaded; I know this because the build produces a "packages" folder that contains "Breeze.EdmBuilder.1.0.4" wherein I see that "edmbuilder.cs" is present and in the right place.
When I issue the command install-package breeze.edmbuilder -version 1.0.4, nuget reports
'Breeze.EdmBuilder 1.0.4' already installed. NugetRestoreFail already has a reference to 'Breeze.EdmBuilder 1.0.4'.
There is nothing wrong with this package AFAIK. For when I uninstall-package breeze.edmbuilder and then reinstall with install-package breeze.edmbuilder -version 1.0.4, the install works and the missing edmbuilder.cs appears in the "App_Start" folder where it belongs.
The failure is repeatable in place.
close the solution
delete edmbuilder.cs from "App_Start"
delete the "packages" folder
optionally delete the .suo and bin and obj directories
re-open the solution and re-build
You'll get the same failing behavior ... and the same ability to manually uninstall and reinstall.
FWIW, removing the reference to edmbuilder.cs from the .csproj has no effect.
No matter what I do, I have to manually uninstall and re-install the package.
WTF!
p.s.: I am using VS 2013 Update 2 RC. I doubt that the "RC" matters as this problem came to my attention from a customer. You never know.
p.p.s: This is not about the build failing and I don't care that this solution would never run. What you see here is a stripped down version of a real app that would have worked. The only question is "why no restored file?"
Package Restore is NOT the same as installing a package. What you are seeing is by design. It simply downloads any missing packages in the packages folder. No more. No less.
Package Restore was added so you wouldn't need to commit the packages folder to source control.
It is expected that you would install a package then commit the changes made to your project files as well as any files that may have been added like your edmbuilder.cs, essentially anything inside your project folder. You would exclude the packages folder.
Now when you get the source from source control everything would be present except for the package files. Package Restore would download those and now your working copy is complete.
See NuGet's Restore Package insists on specific package versions
Is this stupid or what?
Thanks to #Kiliman for explaining that my horrible experience is "by design".
So how do you actually get the content you thought was being restored? Do you install each package one at a time. That's insane.
I was going to observe that there is no nuget equivalent of an npm install that would fetch all the packages you need ... when I discovered that there actually IS an almost-equivalent. It's just not obvious and I wonder how many people know it exists.
It's a two step process:
FIRST restore the missing packages ... THEN
Issue the command: Update-Package -Reinstall
This re-installs all packages in every project in your solution.
If you only want to re-install for a specific project, try:
Update-Package -ProjectName 'YourProjectName' -Reinstall
In both procedures, the -Reinstall switch strives to install the exact versions of the packages spelled out in your package.config ... and not newer "updated" packages which may or may not work for your project (but see the documentation for exceptions).
Read about update-package -reinstall in the official nuget documentation entitled, "Reinstalling Packages and its Pitfalls".
Do not miss the cautionary remarks. Clearly this technique is but an approximation of what you'd expect from other package managers.
Good luck, peoples.