tmaj
tmaj

Reputation: 35037

Azure Pipelines VS Test Task and .net 6

Having the following unit test task

pool:
  name: Azure Pipelines
  vmImage: 'windows-2022' # Needed for .NET6 'windows-latest' did not work 2021 Dec

(...)

- task: VSTest@2
  displayName: "Run unit tests"
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*test*.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'

this task doesn't run any tests and it reports Could not load file or assembly 'System.Runtime, Version=6.0.0.0:

[MSTest][Discovery][...] Failed to discover tests from assembly D:\a\1\s\aaa\bin\Release\net6.0\aaa.dll. Reason:Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

My setup is

Starting: Initialize job
Agent name: 'Azure Pipelines 6'
Agent machine name: 'aaa'
Current agent version: '2.195.2'
Operating System
Virtual Environment
Virtual Environment Provisioner
Current image version: '20211206.1'
Agent running as: 'VssAdministrator'
Prepare build directory.
Set build variables.
Download all required tasks.
Downloading task: DotNetCoreCLI (2.187.0)
Downloading task: VSTest (2.195.0)
Downloading task: PublishPipelineArtifact (1.2.3)
Checking job knob settings.
   Knob: AgentToolsDirectory = C:\hostedtoolcache\windows Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = C:\agents\perflog Source: ${VSTS_AGENT_PERFLOG} 
Finished checking job knob settings.
Start tracking orphan processes.
Finishing: Initialize job

What to do to make it run my beautiful tests?

Upvotes: 1

Views: 2193

Answers (1)

tmaj
tmaj

Reputation: 35037

The issue goes away - the test task finds the tests and runs them - after installing .net 6 explicitly.

steps:
- task: UseDotNet@2 # 2021-Dec Needed for running Unit Test, otherwise https://github.com/microsoft/azure-pipelines-tasks/issues/15607
  displayName: 'Install .net6 runtime (required for running Unit Tests only)'
  inputs:
    packageType: 'runtime'
    version: '6.x'

Upvotes: 1

Related Questions