I am using Find-Package from Powershell 5.0. I need to query for pre-release packages. Is this possible?
I am aware that I can fall back to using nuget.exe list -prerelease if necessary.
It appears that the -AllVersions parameter will include them.
According to the nuget powershell documentation there is the -IncludePreRelease option:
Find-Package [Id] [-Source ] [-First ] [-Skip ] [-AllVersions] [-IncludePrerelease] [-ExactMatch]
Test:
PM> Find-Package Microsoft.AspNet.Identity.EntityFramework -Exact
Microsoft.AspNet.Identity.Entity... {2.2.1}
PM> Find-Package Microsoft.AspNet.Identity.EntityFramework -Exact -IncludePreRelease
Microsoft.AspNet.Identity.Entity... {3.0.0-rc1-final}
In Powershell you have to use the command "-AllowPrereleaseVersions" as documented here:
https://learn.microsoft.com/de-de/powershell/module/packagemanagement/find-package?view=powershell-7.1
Here is the hint on the differences betweeen PackageManager in Visual Studio and in Powershell:
https://learn.microsoft.com/de-de/nuget/reference/ps-reference/ps-ref-find-package
Version 3.0+; this topic describes the command within the Package Manager Console in Visual Studio on Windows. For the generic PowerShell Find-Package command, see the PowerShell PackageManagement reference.
Related
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
I am trying to publish a new version of a Powershell module to the Powershell Gallery by using
Publish-Module -Name "Nuttercode-PRTG" -NuGetApiKey $apiKey -Verbose -RequiredVersion 1.4
The module .psm1 and .psd1 files can be found here.
After dotnet.exe created the package in {myUserDir}\AppData\Local\Temp\{random numbers}\Nuttercode-PRTG it reports:
VERBOSE: finished running C:\Program Files\dotnet\dotnet.exe with exit code 0
VERBOSE: Created Nuget Package
VERBOSE: Successfully created nuget package at
Write-Error: Failed to publish module 'Nuttercode-PRTG': 'Cannot bind argument to parameter 'NupkgPath' because it is an empty string.'.
Afterwards the temp-folder gets deleted. To me this sounds like an internal problem of Publish-Module or dotnet.exe, but I have no idea what is going on or if I am doing something very wrong myself. I also created a new api key just in case but it did not affect the result.
I am using Windows 10 20H2 (Build 19042.1469), Powershell 7.2.2, PowerShellGet 2.2.5, and dotnet.exe 6.0.201. I am able to replicate the problem on another computer using the same command and arguments using Windows 11 21H2 (Build 22000.556), Powershell 7.2.1, PowershellGet 2.2.5, and dotnet.exe 5.0.102.
I am trying to extract a site template of our site(based on the Communication site template) and restore it onto a new one. Whenever I run the below command, I am seeing an error as below
Get-PnPSiteTemplate -Out "C:\bin\ONNProd.xml" -Handlers PageContents,Lists,Pages,Theme,Fields -IncludeAllPages
Get-PnPSiteTemplate : Method not found: 'System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1<Boolean> Enumerator.MoveNextAsync()'.
Checking the version of PnP.Powershell using
Get-Module -Name PnP.PowerShell gives me as 1.7.0
Can some one help me what am i missing?
If you are using VSCode, this could be a bug with the Powershell extension as laid out here https://github.com/microsoft/vscode/issues/120026
I had the same issue, but when running the code from Powershell ISE, it is running now
Sounds like there is a bug with the most recent version (v1.7 and possible v1.6) of PNP.PowerShell for this function. I was able to successfully get this to run by installing the 1.5 version.
Run this to install:
Install-Module PNP.PowerShell -RequiredVersion 1.5.0 -AllowClobber
We install some packages via a PowerShell pre-build script in our CI build. Recently, we're been receiving Partially Successful email notifications with the following information provided:
'Microsoft.CSharp' already has a dependency defined for 'System.Dynamic.Runtime'
Here is the command from the PowerShell script that generates the information:
cd $source\MyNet\MyWeb\MyComp.WebViewer\packages
&"C:\Program Files\Microsoft Team Foundation Server 14.0\Tools\Nuget.exe" install newtonsoft.json
I would like to be able to handle/ignore this message so that fully Successful build notifications are received.
It doesn't seem to be causing any problems otherwise.
Does anyone have any nuget.exe command line parameters that might bypass such an error?
The error message already has a dependency defined for usually indicates that the version of NuGet you are using is too old. So you should look at updating it.
This particular error can happen when the NuGet packages being used are using a group dependency with a target framework which the version of NuGet you are using does not know about.
In my case, I get a message when install some Nuget Package:
'PackageA' already has a dependency defined for 'PackageB'
.
And I search PackageB in Nuget Package Manager online, and click install button to install it again,
then ran into a problem:
The package requires NuGet client version '2.12' or above, but the current NuGet version is '2.7.40911.287'.
and I do as this solution Nuget version not correct?
after I upgrade the version of Nuget Package Manager, I can install PackageB, and then I can install PackageA.
I had a similar problem using NuGet to load the Google.Apis.Sheets.v4.
Upgrading my VS.NET 2013 from NuGet 2.8.60723.765 to 2.12.0.817 resolved it.
To see your NuGet version number, go to the Package Manager Console prompt (PM>) with Tools / NuGet Package Manager / Package Manager Console. Then, enter "$host" at the PM> prompt.
PM> $host
Name : Package Manager Host
Version : 2.12.0.817
InstanceId : 38c7734c-3169-4933-b934-23dab18055f2
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : NuGetConsole.Host.PowerShell.Implementation.NuGetPSHost+Commander
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
PM>
To update NuGet, select Tools / Extensions and Updates... . Then, select "Updates" followed by clicking on the "Update" button of the "NuGet Package Manager".
After the update completes, restart Visual Studio and re-check the NuGet version number.
I'm having an issue packaging my own nuget package, which includes AutoMapper 5.0.2. This is only producing an error within the Visual Studio Team Services (VSTeam) Build servers.
My project is using .NET 4.6.1
Any ideas on how to fix?
Here is the error:
2016-07-08T23:46:44.5801667Z C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.102.0\agent\worker\tools\NuGet.exe pack "C:\a\1\s\Project.csproj" -OutputDirectory "C:\a\1\s\Project\bin\release" -Properties Configuration=release -IncludeReferencedProjects
2016-07-08T23:46:45.0458195Z MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
2016-07-08T23:46:45.0468395Z Attempting to build package from 'Project.csproj'.
2016-07-08T23:46:45.1942694Z Packing files from 'C:\a\1\s\Project\bin\Release'.
2016-07-08T23:46:45.3942642Z ##[error]**'AutoMapper' already has a dependency defined for 'NETStandard.Library'.**
2016-07-08T23:46:45.4142626Z ##[error]System.Exception: Unexpected exit code 1 returned from tool NuGet.exe
2016-07-08T23:46:45.4152639Z ##[error] at Microsoft.TeamFoundation.DistributedTask.Task.Internal.PowerShell.InvokeToolCmdlet.ProcessRecord()
2016-07-08T23:46:45.4152639Z ##[error] at System.Management.Automation.CommandProcessor.ProcessRecord()
I also opened an issue on GitHub: https://github.com/AutoMapper/AutoMapper/issues/1499
You need to install new Nuget version for your visual studio version.
Get it from here
Nuget gallery
I was able to fix/workaround the issue by putting a PowerShell script in to download the latest NuGet. Then I pointed all of the NuGet tasks to this new nuget.exe. Pros: builds are working again, Cons: each build downloads NuGet again, causing unnecessary load on NuGet.org.
Here is my PowerShell:
$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = "$(build.sourcesdirectory)/nuget.exe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
Set-Alias nuget $targetNugetExe -Scope Global -Verbose
nuget
If someone using Team City you also need to use / install newer version of Nuget.