Open gitfool opened 4 years ago
I believe it's a critical issue in the new set of dotnet nuget
commands. Many of them require a source name, and there is no way to interrogate current sources and manipulate them (unless you parse the full output of dotnet nugget list source
).
I'm trying to perform dotnet restore
while building a Docker image, and I want to go through the list of sources and add credentials (PATs) for accessing private feeds. Currently, I can't perform this simple procedure because the full output is not structured, and the short format is missing names.
For now, you can use this regex to filter out name/url pair from the detailed output (use multiline mode)
^\s*\d*\.\s*(.*) \[(?:Enabled|Disabled)\]$[\r\n]+\s*(.*)
Until we get official support, if you have access to PowerShell, you could use this function I wrote to help. It borrows the regular expression from the comment above by @chenghuang-mdsol.
Notes:
function Get-NuGetSourceNameByUrl {
param(
[string]$sourceUrl,
[string]$configFile
)
$nugetSources = $(dotnet nuget list source --configfile $configFile | Out-String)
$sourceName = [regex]::Replace($nugetSources, '(\[(?:Enabled|Disabled)\])\r?\n', '$1', "Singleline") `
-split '\r?\n' `
| Select-String $sourceUrl `
| Select-String "[Enabled]" `
| foreach {[regex]::Replace($_.Line, '^\s*\d+\.\s*(.*) \[(?:Enabled|Disabled)\].*$', '$1')}
return $sourceName
}
@rrelyea I'm playing with the preview of 3.1.200 SDK and
dotnet nuget list source
:My immediate impression is that the short format should also include the source name, in this case
nuget.org
; i.e. I would expect the short format to be succinct but complete:This is backed up by the following experience:
I think the source name is important enough to always be specified, first to avoid the weird default source name, but also because it's required for all other
dotnet nuget ... source
commands, which are source name centric, as shown above.FWIW, I'm currently writing a Cake tool "wrapper" for these
dotnet nuget ... source
commands and a common pattern is to manipulate NuGet sources depending on whether or not a source already exists. A short (single-line) format is better suited to tooling, and given the source name is essential to any such manipulation, I'd argue that it should be included here.