A. Wheatman
A. Wheatman

Reputation: 6396

XUnit tests no longer discovered in .Net Core 2

After moving project from .Net Core 1.1 to .Net Core 2 I just noticed that my xUnit tests are not discovered in VS 2017 anymore...

any ideas how to get them back? :)

UPDATE

After some deeper research I found out that my problem related to this error in my test project: "Could not load file or assembly 'System.Runtime, Version=4.1.1.0"

more details here: https://developercommunity.visualstudio.com/content/problem/95070/could-not-load-file-or-assembly-systemruntime-vers.html

Upvotes: 1

Views: 686

Answers (1)

Dan Clausen
Dan Clausen

Reputation: 61

I ran into the exact same issue and after banging my head for a couple of hours I discovered that xunit in .Net Core 2 requires your Target Framework must be netcoreapp2.0 and not netstandard2.0.

Sample working CS Proj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
  </ItemGroup>

</Project>

Upvotes: 5

Related Questions