3

We're setting up CI/CD for an ASP.NET Core Web API project. We want to run unit tests in the build pipeline from an XUnit project that references the Web API project. This is from our build pipeline:

# azure-pipelines.yml

...

pool:
  vmImage: 'windows-latest'

...

- task: UseDotNet@2
  inputs:
    version: 3.1.x
    packageType: runtime

- task: DotNetCoreCLI@2
  inputs:
    command: build
    projects: '**/MyWebApi.csproj'
    arguments: '--configuration Release'

- task: DotNetCoreCLI@2
  inputs:
    command: test
    projects: '**/MyUnitTests.csproj'
    arguments: '--configuration Release'

...

When we run it, the Web API project is successfully built, but the tests fail to run, giving the following error:

The framework 'Microsoft.AspNetCore.App', version '3.1.0' was not found.

Do we need to extract the classes (from Web API project) that we want to test into another library that doesn't depend on AspNetCore framework? Or can we install the framework on the pipeline agent with a task like UseDotNet@2?

3
  • Pleae try to restore nuget packages before running build and tests. Commented Nov 26, 2020 at 8:33
  • Side note: when you specify 3.1.0, you're explicitly saying you want to use the 3.1.0 version that came out in december 2019. If you want the latest version, you should specify 3.1.x (see the UseDotNet task documentation). Commented Nov 26, 2020 at 9:27
  • @Métoule Thanks, good point. I changed it to 3.1.0 because of the error message, but now I've changed it back to 3.1.x. Commented Nov 26, 2020 at 9:40

1 Answer 1

1

Please change your UseDotnet step and and restore step as follows:

- task: UseDotNet@2
  inputs:
    version: 3.1.x
    packageType: sdk

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.