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.1.0, you're explicitly saying you want to use the3.1.0version that came out in december 2019. If you want the latest version, you should specify3.1.x(see theUseDotNettask documentation).