6

We have a project with a dependency on a custom NuGet feed (also hosted in VSTS).

I'm trying to put together a new phase to generate code coverage reports, as in this blog post. My new phase looks like this:

Screenshot of the new phase

And is made up of the following steps:

  1. .NET Core Tool Installer - use SDK 2.0.0
  2. dotnet restore with my custom feed selected in the "Use packages from this VSTS/TFS feed" drop-down
  3. dotnet test with the relevant arguments to collect code coverage
  4. A custom step using ReportGenerator
  5. A step to publish the results

The problem is that dotnet test insists on trying to restore the packages itself. As I can't find a way to tell it to use a custom feed, it fails when trying to restore these packages:

D:\a\1\s\MyProject\MyProject.csproj : error NU1101: Unable to find package My.Package. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, nuget.org

My main build process works fine and is able to restore the package from the custom feed. The difference is that uses the Visual Studio (i.e. not dotnet) versions of the commands:

Screenshot of the main build process

What's the right way to handle this?

Do I need to find some way to tell dotnet test about my custom feed?

Or (given that I'm running restore immediately prior) do I need to persuade it to skip the restore altogether?

Tom Wright
  • 11,278
  • 15
  • 74
  • 148
  • What if you specify the with **2.1.4** for .NET Core Tool Installer task (or what if you remove the .NET Core Tool Installer task since Hosted VS2017 agent has installed the .net core 2.1.4)? – Marina Liu Aug 15 '18 at 10:32
  • @MarinaLiu-MSFT Thanks for the suggestion, but I've just tried and I'm afraid the behaviour is the same. I've tried setting it explicitly and I've tried disabling the installer task altogether. – Tom Wright Aug 16 '18 at 05:28

4 Answers4

2

I had similar problem with dotnet test and custom nuget feed. The solution was using two steps:

  1. dotnet restore --source (my feed sources)
  2. dotnet test --no-restore

See Implicit restore

Zebemce
  • 21
  • 2
  • Bit late to the party, but when using the DotNetCoreCLI task in Azure DevOps, Microsoft even states your solution explicitly in the docs, see https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/dotnet-core-cli-v2?view=azure-pipelines#why-is-my-build-publish-or-test-step-failing-to-restore-packages – Mike Floyd May 30 '23 at 09:49
1

In case anyone else has this problem, I'm sorry to say our route to resolution was to merge the two repos, effectively negating the need to use the private Nuget feed.

We did have a bit of back and forth with a rep from MS, but didn't get to the bottom of it.

Tom Wright
  • 11,278
  • 15
  • 74
  • 148
0

What's the right way to handle this?

In step dotnet restore, make sure field Path to project(s) specifies all relevant projects. (It's easy to forget a project and that would result in the behavior you experience.) For instance, you can specify the value **/*.csproj. If you do this correctly, other steps such as dotnet test should not even try to restore packages since they have already been restored.

Do I need to find some way to tell dotnet test about my custom feed?

No (assuming step dotnet restore has already restored the packages)

Or (given that I'm running restore immediately prior) do I need to persuade it to skip the restore altogether?

No. It will automatically skip restoring (assuming step dotnet restore has already restored the packages)

lightbricko
  • 2,649
  • 15
  • 21
  • Thanks for your answer @lightbricko. At the time, we definitely checked that we had included all relevant projects. After conversations with MS, I'm pretty sure this was a gap in the .NET Core support, which may well have been resolved in the intervening months. – Tom Wright Jan 31 '19 at 21:28
0

I had the same error on a self hosted build agent. Once I changed the star syntax (get latest version) in the project file to a fixed version the problem went away. I am bit sad that I cant use the version syntax.

Mathias F
  • 15,906
  • 22
  • 89
  • 159