3
votes

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.

3
can you paste the full restore command here?jpgrassi
I didn't use full restore command, because I'm using teamcity UI to perform a buildstep so I passed sources as parameters in teamcity for dotnet restore command. But in the build log it's something like that: dotnet restore -s LocalFolder -s https://api.nuget.org/ . According to Microsoft's docs that should be working, but it's looking for two local folders.star213
Well, that's strange. I don't use teamcity anymore so I can't help much there. What I know is that you can run scripts (like powershell) as a build step. So you could run the dotnet restore as a powershell command. You can still use the TeamCity variables there, just need to pass it to the powershell task.jpgrassi

3 Answers

3
votes

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\`
2
votes

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.

0
votes

I know it should work like that, however using dotnet restore in teamcity build steps allows me to pass sources as parameters on teamcity form. And doing so in one build steps uses below feeds:

C:\\LocalFolder C:\\https:\api.nuget.org\

I've found that remote sources should be passed to teamcity like that: './;https:\api.nuget.org\', but it didn't work also.