CakeBuild: Get failed to install tool 'NUnit.ConsoleRunner' - nunit-console

I used CakeBuild to build and test my Xamarin Portable Class Library.
In the build.cake script I defined that I want to use the NUnit-Console to run my testcases. So I do
#tool nuget:?package=NUnit.ConsoleRunner
Unfortunatelly I get the following error when I run the Cake script.
Preparing to run build script...
VERBOSE: Restoring tools from NuGet...
VERBOSE: Feeds used:
C:\Users\bergkar\.nuget\packages\
All packages listed in C:\dev\Xamarin\fleetboard-core-library\tools\packages.config are already installed.
Running build script...
Analyzing build script...
Processing build script...
Installing tools...
Unable to find package 'NUnit.ConsoleRunner'
NuGet exited with 1
Could not find any relevant files for tool 'NUnit.ConsoleRunner'. Perhaps you need an include parameter?
Error: Failed to install tool 'NUnit.ConsoleRunner'.
When I add a specific version I want to use like below then everything works fine.
#tool nuget:?package=NUnit.ConsoleRunner&version=3.7.0
Can someone tell me why it is not working without the version stuff?
With ".\build.ps1 -Verbosity Diagnostic" I get the following output:
Preparing to run build script...
Running build script...
Module directory does not exist.
Analyzing build script...
Analyzing C:/dev/Xamarin/fleetboard-core-library/build.cake...
Processing build script...
Installing tools...
Installing NuGet package NUnit.ConsoleRunner...
Executing: "C:/dev/Xamarin/fleetboard-core-library/tools/nuget.exe" install "NUnit.ConsoleRunner" -OutputDirectory "C:/d
ev/Xamarin/fleetboard-core-library/tools" -ExcludeVersion -NonInteractive
Unable to find package 'NUnit.ConsoleRunner'
NuGet exited with 1
Feeds used:
Output:
Feeds used:
Could not find any relevant files for tool 'NUnit.ConsoleRunner'. Perhaps you need an include parameter?
Error: Cake.Core.CakeException: Failed to install tool 'NUnit.ConsoleRunner'.
at Cake.Core.Scripting.ScriptProcessor.InstallTools(ScriptAnalyzerResult analyzerResult, DirectoryPath installPath)
at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments)
at Cake.Commands.BuildCommand.Execute(CakeOptions options)
at Cake.CakeApplication.Run(CakeOptions options)
at Cake.Program.Main()

Now I found my problem and solved it.
The problem was that the NuGet.exe did not has a source feed which points to a public nuget source like "https://api.nuget.org/v3/index.json".
This was because my default NuGet.conf in under "C:\Users\YOUR_USER_HOME\AppData\Roaming\NuGet" had no packageSource defined. So Nuget just knows the local nuget package cache under "C:\Users\YOUR_USER_HOME.nuget\packages" and this did not include the specified package.
So after I added a packageSource in "C:\Users\YOUR_USER_HOME\AppData\Roaming\NuGet\NuGet.Conf" everything works fine.
Another way can be to add a new NuGet.Conf beside your build.ps1 file which contains all package sources you need for CakeBuild and your Xamarin project.
The following page explains how Nuget finds its configuration. Maybe this is helpful to understand the mechanism NuGet uses to find its configuration:
https://learn.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior

Related

How to create a Nuget Package in ADO Pipeline

Using the Classic DevOps, I am trying to create a NuGet package out of one of our code libraries.
I am Using NuGet version 5.9.1
I am able to do a NuGet restore of the 'Newtonsoft.Json.13.0.1.nupkg' dependency. The task succeeds without an error:
[![enter image description here][1]][1]
I am able to compile the project in VS in the pipeline
However, when I try to NuGet pack the same project that is used in the Restore Step above, I get this error:
##[error]The nuget command failed with exit code(1) and error(Error NU5012: Unable to find 'Newtonsoft.Json.13.0.1.nupkg'. Make sure the project has been built.
I have tried various combinations of Destination Directors on the Restore and Base Path in the Pack but still get that error or this one:
##[error]The NuGet command failed with exit code(1) and error(Cannot determine the packages folder to restore NuGet packages. Please specify either -PackagesDirectory or -SolutionDirectory.
I cannot find any documentation that explains how to do this.
How does one build this type of Pipeline?
Thanks for your help!
Updated:
this is the example i used when i receive the error
Apparently the package was installed from NuGet.org:
Installed Newtonsoft.Json 13.0.1 from https://api.nuget.org/v3/index.json with content hash ppPFpBcvxdsfUonNcvI etc.
Adding package 'Newtonsoft.Json.13.0.1' to folder 'D:...$(Build.ArtifactStagingDirectory )'
PackageSignatureVerificationLog: PackageIdentity: System.Runtime.4.3.1 Source: https://api.nuget.org/v3/index.json PackageSignatureValidity: True
Added package 'Newtonsoft.Json.13.0.1' to folder 'D:...$(Build.ArtifactStagingDirectory )'
Added package 'Newtonsoft.Json.13.0.1' to folder 'D:...$(Build.ArtifactStagingDirectory )' from source 'https://api.nuget.org/v3/index.json'
But I get this error on the Pack:
C:\hostedtoolcache\windows\NuGet\5.9.1\x64\nuget.exe pack D:\MyApp.Applications.Framework.Json.Converters.csproj -NonInteractive -OutputDirectory D:\a\1\a -BasePath D:\a\1\a -Properties "Configuration=Release" -IncludeReferencedProjects -version 2022.05.24.1 -Verbosity Detailed
Error NU5012: Unable to find 'Newtonsoft.Json.13.0.1.nupkg'. Make sure the project has been built.
Further Update:
I seem to be able to restore the NewtonSoft package:
PackageSignatureVerificationLog: PackageIdentity: Newtonsoft.Json.13.0.1 Source: https://api.nuget.org/v3/index.json PackageSignatureValidity: True
Installed Newtonsoft.Json 13.0.1 from https://api.nuget.org/v3/index.json with content hash ##
Adding package 'Newtonsoft.Json.13.0.1' to folder 'D:\a\1\s\XM\packages'
Added package 'Newtonsoft.Json.13.0.1' to folder 'D:\a\1\s\XM\packages'
Added package 'Newtonsoft.Json.13.0.1' to folder 'D:\a\1\s\XM\packages' from source 'https://api.nuget.org/v3/index.json'
Restoring NuGet package System.Net.Http.4.3.4.
However, the NuGet Pack step cannot find it:
Attempting to pack file: D:\a\1\s\XM\Applications\Framework\Json\Converters\XM.Applications.Framework.Json.Converters\XM.Applications.Framework.Json.Converters.csproj
C:\hostedtoolcache\windows\NuGet\5.9.1\x64\nuget.exe pack D:\a\1\s\XM\Applications\Framework\Json\Converters\XM.Applications.Framework.Json.Converters\XM.Applications.Framework.Json.Converters.csproj -NonInteractive -OutputDirectory D:\a\1\a -Properties Configuration=Release -IncludeReferencedProjects -version 2022.05.24.14 -Verbosity Detailed
Error NU5012: Unable to find 'Newtonsoft.Json.13.0.1.nupkg'. Make sure the project has been built.
Seems that the pack step doesn't see the nupkg. How can i tell the pack step where to find it?
[1]: https://i.stack.imgur.com/ME7M6.png

VSTS Release Task - Push to Nuget

I'm trying to set up CI for my Core projects and wrappers to our vsts nuget feed.
I've followed the Zen of Package Management tutorial here.
It's a little out of date, but I believe I managed to translate the changes.
My Build seems to work fine, it builds and packages the dll's into several nuget packages.
The release seems to work also, but the Nuget Feed is not updated with the latest packages.
My Release task is only one task as shown in the image below.
The log shows that it found and downloaded the packages, but it does not show any success on the actual push to nuget.
This is the log that shows the packages being found, and successful completion.
2017-11-15T02:40:59.5675003Z ##[section]Finishing: Initialize Job
2017-11-15T02:40:59.6125167Z ##[section]Starting: Download Artifacts
2017-11-15T02:41:00.2861639Z Downloading artifact
2017-11-15T02:41:00.2961643Z Creating artifacts directory: d:\a\r1\a
...etc
2017-11-15T02:41:00.8313684Z Downloading file d:\a\r1\a\Satalyst-Visual Studio-CI\drop\release\Packaged\Satalyst.AzureWrapper.Domain.2.0.0.3.nupkg
2017-11-15T02:41:00.9943663Z Downloading file d:\a\r1\a\Satalyst-Visual Studio-CI\drop\release\Packaged\Satalyst.PaymentGateway.Interfaces.2.0.0.3.nupkg
2017-11-15T02:41:00.9998063Z Downloading file d:\a\r1\a\Satalyst-Visual Studio-CI\drop\release\Packaged\Satalyst.PaymentGateway.Test.2.0.0.3.nupkg
...etc
2017-11-15T02:41:01.0750176Z Download complete.
2017-11-15T02:41:01.0761342Z 16 placed file(s): 16 downloaded, 0 empty
2017-11-15T02:41:01.0830178Z 1 MB downloaded at 1491 KB/sec. Download time: 00:00:00.2761869.
2017-11-15T02:41:01.0830178Z Downloaded linked artifact Satalyst-Visual Studio-CI
2017-11-15T02:41:01.0830178Z Finished artifacts download
2017-11-15T02:41:01.0890187Z ##[section]Finishing: Download Artifacts
... its this bit below that succeeds, but the feed does not show the new packages??
2017-11-15T02:41:01.0920188Z ##[section]Starting: NuGet Publish
2017-11-15T02:41:01.1190170Z ==============================================================================
2017-11-15T02:41:01.1190170Z Task : NuGet
2017-11-15T02:41:01.1190170Z Description : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Package Management and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
2017-11-15T02:41:01.1190170Z Version : 2.0.15
2017-11-15T02:41:01.1190170Z Author : Microsoft Corporation
2017-11-15T02:41:01.1190170Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613747)
2017-11-15T02:41:01.1190170Z ==============================================================================
2017-11-15T02:41:04.1372760Z Caching tool: NuGet 4.1.0 x64
2017-11-15T02:41:04.1502760Z Found tool in cache: NuGet 4.1.0 x64
2017-11-15T02:41:04.1612765Z Resolved from tool cache: 4.1.0
2017-11-15T02:41:04.1612765Z Using version: 4.1.0
2017-11-15T02:41:04.1612765Z Found tool in cache: NuGet 4.1.0 x64
2017-11-15T02:41:05.1667858Z [command]C:\Windows\system32\chcp.com 65001
2017-11-15T02:41:05.1667858Z Active code page: 65001
2017-11-15T02:41:05.1877908Z ##[section]Finishing: NuGet Publish
2017-11-15T02:41:05.1937859Z ##[section]Finishing: Release
Any assistance would be greatly appreciated, I've been doing a bit of trial and error to find the issue with no success. I'm now a bit stuck with no error messages and no feedback on the outcome for the push.
It's caused by the configuration of Path to NuGet package(s) to publish option for NuGet Push task in your release definition.
Please change the Path to NuGet package(s) to publish as:
$(System.DefaultWorkingDirectory)/**/packed/*.nupkg
Then the nuget package should be published to your feed correctly.

NuGet restore works if old version 0.*, but fails with version 2.*

I've got a VSTS build, starting from a blank, originally with just Node.js bits, but now adding some C# bits.
Added the NuGet restore, build sln and vstest tasks as part of the update to the build.
Build fails on the NuGet restore task with the error around the MSTest TestAdapter ...
Restoring NuGet package MSTest.TestAdapter.1.1.11.
Restoring NuGet package MSTest.TestFramework.1.1.11.
WARNING: Unable to find version '1.1.11' of package 'MSTest.TestFramework'.
WARNING: Unable to find version '1.1.11' of package 'MSTest.TestAdapter'.
Errors in packages.config projects
Unable to find version '1.1.11' of package 'MSTest.TestFramework'.
Unable to find version '1.1.11' of package 'MSTest.TestAdapter'.
Why doesn't it pick up the MSTest package?
And even more puzzling to me ??? ...
I spotted the task was version 2.*
tried setting it to version 0.* ...
and the build works !! ... runs tests, etc.
Why does version 0.* work, yet the latest version 2.* fails?

Unsupported framework error NUnit and MonoDevelop

I have latest versions of MonoDevelop(5.10) and NUnit(3.6.1 installed from oficiall NuGet Gallery) and every time I'm trying to run tests I'm getting error
UnsupportedFrameworkException: Skipped loading assembly ... because it references an unsupported version of the nunit.framework 3.6.1.0
What can I do about it ?
You are apparently trying to run the tests from inside of MonoDevelop, which only supports NUnit through 2.4.8.
You need to install and run the nunit console runner. Use the NUnit.ConsoleRunner nuget package and run nunit3-console, which is contained in the package.

Team Services: Nuget Packager task failing

I have a Build definition in Team Services that includes a Nuget Packager task. I'm using Hosted build agents.In the last couple of builds this task began to fail, with the following message:
2017-02-22T21:43:24.9318762Z C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.112.0\externals\nuget\NuGet.exe pack "D:\a\1\s\src\app\Ormie\Ormie.csproj" -OutputDirectory "D:\a\1\s" -Properties Configuration=release
2017-02-22T21:43:25.5460318Z MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
2017-02-22T21:43:25.5460318Z Attempting to build package from 'Ormie.csproj'.
2017-02-22T21:43:25.7480272Z Packing files from 'D:\a\1\s\src\app\Ormie\bin\Release'.
2017-02-22T21:43:25.9040273Z Using 'Ormie.nuspec' for metadata.
2017-02-22T21:43:26.1645370Z ##[error]'System.Collections' already has a dependency defined for 'Microsoft.NETCore.Platforms'.
2017-02-22T21:43:26.1865365Z ##[error]System.Exception: Unexpected exit code 1 returned from tool NuGet.exe
2017-02-22T21:43:26.1865365Z at Microsoft.TeamFoundation.DistributedTask.Task.Internal.InvokeToolCmdlet.ProcessRecord()
2017-02-22T21:43:26.1865365Z at System.Management.Automation.CommandProcessor.ProcessRecord()
2017-02-22T21:43:26.2015355Z ##[error]PowerShell script completed with 1 errors.
2017-02-22T21:43:26.2025352Z ##[section]Finishing: NuGet Packager
In order to understand what was happening, I tried to create the package in my development box, using NuGet version 3.3, and got a similar message. So, I've updated NuGet to version 3.5, tried to pack in my machine and it worked just fine.So, my questions are:
Is there any kind of configuration in Team Services Build Definition
that can be done to solve this issue?
How can I force the Hosted build agent to use version 3.5 in the
NuGet Packager task?
To use nuget3.5 for nugget packager task, you can add nugget.exe to source control, and then use $(Build.SourcesDirectory)\nuget.exe as path to nugget.exe.
For Nuget Restore and Nuget Publisher Tasks, they define 3.3 and 3.5 in their tasks. You can view task.json for all tasks definitions in VSTS task.
If you want Nuget Packager also can choose nugget version, you should develop your own task same as Nuget Packager function and with nuget version to choose.