Azure pipelines task VSTest@2 failing with error - Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.Common.resources'

Viewed 1338

I’ve created .Net Core 3.1 API test case projects. My project has the following nugget packages.

  • Microsoft.NET.Test.Sdk 15.3.0
  • Moq 4.16.1
  • xunit - 2.4.1
  • xunit.runner.visualstudio - 2.4.3

The unit test project executes properly in VS 2019 and all my test cases are passed. In the deployment yaml file, I’ve the following code.

- task: VSTest@2
 - inputs:
     platform: '$(buildPlatform)'
     configuration: '$(buildConfiguration)'

This task fails with tons of errors

2021-03-03T18:33:16.4990294Z [MSTest][Discovery][D:\a\1\s\API\MyProject.ApiTests\bin\Release\netcoreapp3.1\cs\Microsoft.VisualStudio.TestPlatform.Common.resources.dll] Failed to discover tests from assembly D:\a\1\s\API\MyProject.ApiTests\bin\Release\netcoreapp3.1\cs\Microsoft.VisualStudio.TestPlatform.Common.resources.dll. Reason:Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.Common.resources' or one of its dependencies. The system cannot find the file specified.
2021-03-03T18:33:16.5032225Z [MSTest][Discovery][D:\a\1\s\API\MyProject.ApiTests\bin\Release\netcoreapp3.1\cs\Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll] Failed to discover tests from assembly D:\a\1\s\API\MyProject.ApiTests\bin\Release\netcoreapp3.1\cs\Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll. Reason:Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.ObjectModel.resources' or one of its dependencies. The system cannot find the file specified.
2021-03-03T18:33:16.5033961Z [MSTest][Discovery][D:\a\1\s\API\MyProject.ApiTests\bin\Release\netcoreapp3.1\de\Microsoft.TestPlatform.CommunicationUtilities.resources.dll] Failed to discover tests from assembly D:\a\1\s\API\MyProject.ApiTests\bin\Release\netcoreapp3.1\de\Microsoft.TestPlatform.CommunicationUtilities.resources.dll. Reason:Could not load file or assembly 'Microsoft.TestPlatform.CommunicationUtilities.resources' or one of its dependencies. The system cannot find the file specified.

and so on.

I tried upgrading/downgrading Microsoft.NET.Test.Sdk versions, but no luck. Any help would be highly appreciated.

2 Answers

In our projects, we do a couple of things: make sure the right tool set is installed, and be specific about the test path:

          - task: VisualStudioTestPlatformInstaller@1
            displayName: 'Install Visual Studio Test Platform'
            inputs:
              packageFeedSelector: 'nugetOrg'
              versionSelector: 'latestStable'
          - task: VSTest@2
            displayName: 'Run Unit Tests'
            inputs:
              vsTestVersion: 'toolsInstaller'    
              # our test projects all have ".Tests" in the name
              testAssemblyVer2: '**/bin/$(buildConfiguration)/*.Tests.dll'
              platform: '$(buildPlatform)'
              configuration: '$(buildConfiguration)'
              codeCoverageEnabled: true
              runTestsInIsolation: true

The above answer from WaitingForGuacamole worked along with an upgrade to Microsoft.NET.Test.Sdk to 16.9.1. Thanks.

Related