Force NuGet Commandline List to NOT use Wildcards - nuget

I'm trying to use the NuGet command line to get the latest version of a package in a repo as part of an MSBuild task. Unfortunately there are three packages which all start with the same thing, for example:
MyCorp.ThirdPartyServices
MyCorp.ThirdPartyServices.DB
MyCorp.ThirdPartyServices.OtherStuff
Therefore the command
nuget.exe list -Source http://mycorp.repo/nuget MyCorp.ThirdPartyServices
Returns all three entries as I'm assuming it's internally adding a wildcard to the end of the search term. Whilst I can deal with this, I'd rather not have to. Is there any way to search for an exact package name or do I just have to suck it up and parse whatever comes out?

You should be able to use a special search syntax to filter the result. The following works on nuget.org:
nuget.exe list packageid:NUnit
This just returns the single NUnit package.
Here I am using NuGet v2.

Related

Call a chocolatey package in powershell based on its package name

I recently set up a new machine and installed/enabled chocolatey. As far as I can remember I was able to call a package via powershell based on the package name. For instance, if I wanted to install mongodb, I used to type choco install mongodb - and was able to call the mongo client by simply typing mongo in the powershell console. Is there a way to see if something is bound to a specific shim ? or is there an option to enable it?
I don't think there is a way to match packages with shims, but you can check the executable a shim points to, along with general information about it and what would happen if you run the shim:
shimname.exe --shimgen-noop
I tried crafting a command to check all the shims in the $env:ChocolateyInstall\bin directory, but there's no guarantee that executables there are going to be a shim. I tried filtering out the known Chocolatey executables as well, but some packages (like putty) drop their real executables right in the bin folder, and won't respond to the shim parameters like you'd expect.
Looking at the Install-BinFile cmdlet, it doesn't look like Chocolatey provides a way to track shims at all as it doesn't even do this itself. I think it uses the same logic to track automatically generated shims at package uninstall time, but any shims explicitly created with Install-BinFile also need to have Uninstall-BinFile called in the associated chocolateyUninstall.ps1 script or the shim won't be removed at package uninstall time.
Short of crawling the $env:ChocolateyInstall\lib\packageName directory for potential automatic shim names, or the chocolateyInstall.ps1/chocolateyUninstall.ps1 scripts for explicit shims, you're not going to be able to match a shim to a package.

How can I create executable package for OneGet Install-Package?

I understand how to create a package for NuGet. There's also nothing especially hard with creating a NuGet package or PowerShell package.
I'm aware it may be impossible to create PowerShell package with binary cmdlet in .NET Core, so wondering if it's possible to create a package with lifecycle hooks.
Say, in npm, you can define scripts in package.json to declare pre/post install/publish dependencies.
So, the question is:
How can I perform custom script after having my package added to the system via Install-Package?
For example, I want to add executable to PATH (likely to be pretty common task)
Likely, this one will work:
project.json#scripts
Note, that valid values are allowed platform executables, so, as I got that, PowerShell is not allowed by default.
Quick workaround, as far as arguments are available:
runner.cmd:
#powershell -File %1
and in project.json:
"scripts": {
"postrestore": "%project:Directory%/scripts/runner.cmd %project:Directory%/scripts/install.ps1"
}

Do I not understand Nuget Get-Package Syntax?

This should return a list of all versions right?
Nuget.org, my package source, hosts a lot of versions for this package.
Here they are.
Can someone tell me what I am missing?
The -AllVersions parameter is part of the "Remote" parameter set which includes your parameters so it looks like the parameters are correct.
Looking at the request that is returned from https://nuget.org/api/v2/Search() it does not look like what you are trying to do is supported.
The raw data sent back does not include multiple versions for each NuGet package so, even though there is code in NuGet which does not collapse the versions down to the latest when -AllVersions is specified as it displays the results, you only get the one version for each NuGet package.
The -AllVersions parameter seems to only work when the -Updates parameter is used. This uses a different query https://nuget.org/api/v2/GetUpdates() which returns multiple package versions. So you can only see all NuGet package versions for the updated packages in your project.
Get-Package -AllVersions -Updates -Filter jquery

How to make NuGet pack not overwrite an existing version

When building a NuGet Pack to an output directory, I do not want it to overwrite an existing version
Existing command:
".nuget\nuget.exe" pack "some.csproj" -output "c:\~packages"
I have looked through the documentation and cannot seem to find a switch that does it. I tried using a if exists "c:\~packages\some.nupkg" exit 1 but the problem is I do not have access to the version number in that context, so I cannot predictably provide a version to check for
This is not currently possible using NuGet.exe.
The options are:
Modify NuGet's source code to allow an extra command line option to support not overwriting the existing NuGet package if it exist. The PackCommand could be changed to support this.
Write a utility to generate the correct package version, then check the package exists before running NuGet.exe. The package version information is read from the AssemblyInformationalVersionAttribute taken from the project's output assembly if you are using nuget pack projectfile.

How to include current package version in NuGet transformation files?

I would like to include a content file into the package that should refer to the current version of the package being installed (more precisely to the package folder, but the only varying part is the version).
Is there a special syntax (e.g. $packageversion$ - does not work) to include the version number into a transformed (.pp) content file?
Alternative: I can access the version from the install.ps1 and I can also invoke Add-Content (i suppose that will also apply the transformations), but how can I extend the replacement placeholders?
The variables you can use (like $rootnamespace$) are the ProjectProperties so you won't be able to access the version number.
As a workaround, you could try naming the file as part of your build step that creates the NuGet package.
If you think it'd be good to see this added to NuGet, it's worth starting a discussion on the NuGet site, the developers are pretty active there :-)