CSharpRepl
CSharpRepl copied to clipboard
Allow specifying the source when adding a nuget package with #r
Feature Description
Context
I tried to add Newtonsoft.Json
nuget package using #r "nuget: Newtonsoft.Json"
on csharprepl
and I got this error:
Description
You can have many sources enabled in nuget configuration (you can list them by running nuget sources
or dotnet nuget list source
commands)
but some of them (for example company private package sources) may not be accessible sometimes (authentication or vpn may be needed, etc.). nuget.org should always be a safe and accessible source, but if the nuget command tries an inaccessible one it fails
I don't know how it works but the nuget add
command requires a source as an argument, but the dotnet add package
does not, it is optional so I am guessing that it iterates over all sources maybe? I really don't know. I do know that you can enable and disable sources via command line or editing the nuget config xml file, but it is kind of annoying
The error with csharprepl
today was because it tried to access my company's private repo and got an auth error
I get the same error when I use dotnet add package
command directly:
Feature Request
It is possible to extend the #r
command to accept a source or do something like --ignore-failed-sources
on dotnet restore
command?
I spent some time looking into this, and ultimately we're blocked on https://github.com/NuGet/Home/issues/7304 / https://github.com/NuGet/Home/issues/5643. There's a very promising looking SourceCacheContext.IgnoreFailedSources
property available to us, but the underlying NuGet APIs don't actually respect it.
A potential workaround (untested) would be to reorder the sources in the NuGet.config file -- from what I can tell they're tried in the same order that they're listed in the file.