0

I'm currently working on a YAML pipeline in Azure pipelines and have run into a snag. I already have a work around; however, I was curious if anyone has encountered this and solved for it properly. Here is the issue.

I have a project that contains multiple solutions. Some solutions are utilizing package.config and others are using PackageReference. This wasn't really a big deal until we got to performing a nuget restore on the solutions within the project using the task below.

- task: NuGetToolInstaller@1
  displayName: 'Detect\Install NuGet'
- task: NuGetCommand@2
  displayName: 'Restore NuGet Packages'
  inputs:
    restoreSolution: '**\*.sln'
    feedsToUse: 'config'
    command: 'restore'

The tasks above successfully detect an existing NuGet installation, if not it install the latest version of NuGet. Then it performs a nuget restore of all packages using PackageReference. This is where the rub comes into play. Any solutions that are utilizing package.config are skipped by this task since it defaults to the PackageReference solutions. To get around this issue we have added an additional NuGet command task that we point to a local nuget.config file within our repository.

Note: The first task utilizes the system default nuget.config file configured on our pipeline agents.

- task: NuGetCommand@2
  displayName: 'Restore NuGet Packages for package.config'
  inputs:
    restoreSolution: '**\*.sln'
    feedsToUse: 'config'
    nugetConfigPath: 'nuget.config'

While this isn't adding a large amount of time to your builds, it still isn't ideal as it would be nice to utilize a single task. Any help would be greatly appreciated.

Thanks, Source Code

Source Code
  • 201
  • 1
  • 7
  • I create a testing solution with PackageReference project and package.config project. I used the nuget restore task. And it can restore both the projects. Can you share the task log how the package.configs are skipped? You can test your pipeline on self-hosted machine to check if the packages in packages.config are restored. In my test pipeline, the log showed `Restoring NuGet package..` when restoring packages.config , and showed `Restoring packages for C:\AgentWicre\_work\21\s\EvenNumber\OddTest\OddTest.csproj` when restoring PackageReference. – Levi Lu-MSFT Jul 02 '20 at 09:56
  • You may migrate from package.config to packagereference: [Migrate from packages.config to PackageReference](https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference) – starian chen-MSFT Jul 10 '20 at 11:47

0 Answers0