Skip to content

MSTest.Sdk 4.0.2 has conflicting transitive dependencies of Microsoft.CodeCoverage.Core #15387

@vmrz

Description

@vmrz

When using MSTest.Sdk 4.0.2 it implicitly includes conflicting versions of Microsoft.CodeCoverage.Core through:

  • Microsoft.NET.Test.Sdk 18.0.1 → Microsoft.CodeCoverage 18.0.1 (contains DLL v18.0.6.0)
  • Microsoft.Testing.Extensions.CodeCoverage 18.1.0 (contains DLL v18.1.0.0)

Because of that, running a published test project leads to runtime error:

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeCoverage.Core, Version=18.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'Microsoft.CodeCoverage.Core, Version=18.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Microsoft.Testing.Extensions.TestingPlatformCoverageExtensions.AddCodeCoverageProvider(ITestApplicationBuilder builder)
   at Microsoft.Testing.Extensions.TestingPlatformCoverageExtensions.AddCodeCoverageProvider(ITestApplicationBuilder builder)
   at Microsoft.Testing.Extensions.CodeCoverage.TestingPlatformBuilderHook.AddExtensions(ITestApplicationBuilder testApplicationBuilder, String[] _)
   at StatusUpdate.Smoke.Tests.SelfRegisteredExtensions.AddSelfRegisteredExtensions(ITestApplicationBuilder builder, String[] args)

Version used

MSTest.Sdk 4.0.2

Steps To Reproduce

  1. Create a new test project with MSTest.Sdk. Do not include any additional references.
<Project Sdk="MSTest.Sdk/4.0.2">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
  </PropertyGroup>
</Project>
  1. dotnet run - tests are executed successfully.
  2. Execute dotnet publish --configuration Release
  3. cd bin/Release/net10.0/publish
  4. dotnet TestProject1.dll - runtime exception.

Repo with reproduceable issue: https://github.com/vmrz/MSTest-4.0.2-Microsoft.CodeCoverage.Core-conflict

Expected behavior

Published tests are ran successfully.

Actual behavior

Runtime exception.

Additional context

Tests work fine with release and debug builds. This only impacts publish build.

Current workaround to the problem is explicitly excluding coverage package assets to avoid version conflict:

<PackageReference Include="Microsoft.CodeCoverage" Version="18.0.1">
  <ExcludeAssets>all</ExcludeAssets>
</PackageReference>

Issue can be reproduced using Microsoft.NET.Sdk and MSTest 4.0.2 as a package reference as well:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <EnableMSTestRunner>true</EnableMSTestRunner>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
 
  <ItemGroup>
    <PackageReference Include="MSTest" Version="4.0.2" />
  </ItemGroup>
</Project>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions