In our company we are behind HTTP proxy, so we need to use it when accessing nuget.org to restore packages.
We also use an internal NuGet server where we publish some shared components packaged as NuGet.
When running CI build we want to restore packages from both sources. Is there any way to configure NuGet to use proxy for one but not the other?
If I define a http_proxy in NuGet.config it's used for both sources, hence failing with the internal one. If I don't define it, it fails with global source.
I've ended up deliberately calling "nuget restore" twice, as a separate step in CI build before the main MsBuild for solution.
First call is for global source with proxy, second call - for local source without proxy. It still complains on the first run about packages not found which live in local source, so I'm ignoring the exit code of the first run.
Here is the Windows batch code I've used in our CI build (in TeamCity):
set NUGET_PATH="%system.SolutionDirectory%\.nuget\NuGet.exe"
set NUGET_GLOBAL=https://www.nuget.org/api/v2/
set NUGET_LOCAL=%teamcity.nuget.feed.server%
echo Restoring from global source with proxy
set http_proxy=%env.http_proxy_global%
%%NUGET_PATH%% restore "%system.SolutionDirectory%\%system.SolutionFile%" -NonInteractive -Source %%NUGET_GLOBAL%%
echo --- Finished with exit code: %%ERRORLEVEL%%
echo Restoring from local source without proxy
set http_proxy=
%%NUGET_PATH%% restore "%system.SolutionDirectory%\%system.SolutionFile%" -NonInteractive -Source %%NUGET_LOCAL%%
echo --- Finished with exit code: %%ERRORLEVEL%%
exit %%ERRORLEVEL%%
Bear in mind, syntax here is specific to TeamCity, i.e. double percentage signs are used to enclose env vars, because single ones are to reference a TeamCity parameter.