There is a better alternative imo. You can continue using your script to dotnet restore
.
Simply add a task just before that with NuGetAuthenticate@0
steps:
- task: NuGetAuthenticate@0
- script: dotnet restore --no-cache --force
this task will authenticate the pipeline with the nuget feeds that require so and are found at the NuGet.config
file.
Notice that when the nuGet feed is within Azure DevOps there is nothing else required. If the feed is external you can configure at your Azure DevOps a nuGet Service Connections (at the link there is further info).