How to run dotnet test on VSTS with custom NuGet feed?

3.2k views Asked by At

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?

4

There are 4 answers

0
Tom Wright On BEST ANSWER

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.

0
Mathias F On

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.

1
lightbricko On

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)

1
Zebemce On

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