Msbuid nuget restore failing

John David 1 Reputation point
2022-09-28T23:25:30.227+00:00

Trying to setup an Azure App Service. Source code is in github. This .NET project builds and runs fine on local Visual Studio 2022. The App Service deployment is pretty much stock that Azure created. It grabs the code from github and then further along attempts a nuget restore. The packages that are from the default path https://api.nuget.org are fine. The problem is that some packages are from https://api.anotherfeedsite.org and nuget restore still tries to find these in https://api.nuget.org.

All the search material that's coming up only has the package sources specified in Visual Studio https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore which is great as it works on local. On the runner, I obviously don't have access to the Visual Studio to specify additional package sources. As far as I can tell adding additional package source in local Visual Studio does not change anything in the project source code/solution file so looks like that is stored in the "Visual Studio Settings" itself.

How is the runner that is doing the build expected to find the package sources/feed URLs if it's not the default https://api.nuget.org?

EDIT #1
Actually, got one step closer. Found nuget.config and added the feeds there. Now trying to change the yml to look at the nuget.config

name: Build and deploy ASP app to Azure Web App  
  
on:  
  push:  
    branches:  
      - main  
  workflow_dispatch:  
  
jobs:  
  build:  
    runs-on: windows-latest  
  
    steps:  
      - uses: actions/checkout@v2  
  
      - name: Setup MSBuild path  
        uses: microsoft/setup-msbuild@v1.0.2  
  
      - name: Setup NuGet  
        uses: NuGet/setup-nuget@v1.0.5  
  
      - name: Restore NuGet packages  
        run: nuget restore -ConfigFile 'nuget.config'  

This gives an error File 'D:\a\MYAPP\nuget.config' does not exist. Any idea what syntax should be here?

I got the setup working in Azure pipelines... where the yaml is quite different so I can't really copy/paste.

- task: NuGetCommand@2  
  inputs:  
    restoreSolution: '$(solution)'  
    feedsToUse : 'config'  
    nugetConfigPath: 'nuget.config'  

Regards,

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,407 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 27,111 Reputation points Microsoft Employee
    2022-09-29T03:08:52.673+00:00

    Have a look at https://learn.microsoft.com/en-us/azure/devops/pipelines/packages/nuget-restore?view=azure-devops&tabs=classic. Make sure your nuget.config file is the same directory as your project/sln or just add key referencing your nuget source in the csproj. This should allow you to utilize either the nuget restore task or msbuild running on the agent to pull the packages from the additional sources.

    Another option is using Artifacts within Azure DevOps where you could push the nuget packages your project requires and pull them from that source during the pipeline build; but I would use this as the last alternative unless I was the one creating the packages the project needed.