Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dotnet restore using local and server sources

I would like to use dotnet restore command to provide two sources using --source flag. First one is in local folder inside project files and second one is on remote server (actually it's official nuget source).

I used dotnet restore inside teamcity and passed sources as parameters as follow:

LocalFolder https://api.nuget.org/

However when teamcity builds my pipeline, dotnet restore search for packages firstly inside C:\BuildAgent\work\LocalFolder, which is fine - that's what I wanted. But in next step it's looking for second source in C:\BuildAgent\work\https://api.nuget.org/ which is obviously wrong.

I dont know how to combine two sources within one dotnet restore command when one of the sources is local and second one is hosted on the server. Is there any workaround for that?

@Edit I know I can create two build steps with seperate dotnet restore commands. One for local source and second one for server. However It would be nice to combine it within one command.

like image 810
star213 Avatar asked Jan 26 '26 00:01

star213


2 Answers

You can provide the source argument multiple times to the dotnet restore command, to feed it multiple sources:

-s|--source <SOURCE>

Specifies a NuGet package source to use during the restore operation. This setting overrides all of the sources specified in the NuGet.config files. Multiple sources can be provided by specifying this option multiple times.

So, you can run:

dotnet restore -s YourPackagesFolder -s https://api.nuget.org/

If you run it with --verbosity n you can see the output:

Feeds used:
             C:\<projectlocaltion>\LocalFolder
             https:\api.nuget.org\`
like image 95
jpgrassi Avatar answered Jan 29 '26 00:01

jpgrassi


In case someone else stumbles across this, I wasn't able to find the actual root cause of the issue but I was able to resolve it by putting remote references BEFORE local references in my source list.

like image 40
MrJackSpade Avatar answered Jan 28 '26 23:01

MrJackSpade



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!