1
votes

I am trying to set up a project and unit test it with xUnit, coding in C#. I followed the steps in this guide https://xunit.github.io/docs/getting-started-dotnet-core.html But I had an error "The specified framework version '2.0' could not be parsed The specified framework 'Microsoft.NETCore.App', version '2.0' was not found. - Check application dependencies and target a framework version installed at: / - Alternatively, install the framework version '2.0'."

To fix this, I tried specifying the runtimeframeworkversion to 2.1.0 as dotnet --version 2.1.200

I now get an error that is unable to find Unable to find package Microsoft.NETCore.App with version (>= 2.1.0) despite what is returned by dotnet --version.

Any help would be apprciated thanks.

My current proj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="xunit" Version="2.3.1"/>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1"/>
</ItemGroup>
</Project>

I am also running OSX High Sierra

2
What is the output of dotnet --version at Terminal? Don't use "RuntimeFrameworkVersion" unless you know what you are doing.Lex Li
@LexLi 2.1.200 you're right quite I don't know what I'm doing I just figured if I have 2.1.200 I could try run version 2.1.0rb20

2 Answers

2
votes

Try install version 2.0.3 and setup config for it. Also maybe you will need add strings after line <PackageReference Include="xunit" Version="2.3.1"/>:

<PackageReference Include="xunit.runner.console" Version="2.3.1" />
<PackageReference Include="xunit.runner.msbuild" Version="2.3.1" />

I used it for linux and it worked. But it can help you.

0
votes

I post my own configuration here , maybe it helps.

The project is a Library named DataStructures , testing it with Xunit :

The Tests.csproj :

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\DataStructures\DataStructures.csproj" />
  </ItemGroup>

</Project>

. .

The Launch.json(Gist) :

{

    "version": "0.2.0",
    "configurations": [
        {
            "name": "Build_DataStructures",
            "type": "coreclr",
            "request": "launch",
            "program": "dotnet",
            "args": ["build"],
            "cwd": "${workspaceFolder}/DataStructures",
            "console": "integratedTerminal"
        },
        {
            "name": "Run_Tests",
            "type": "coreclr",
            "request": "launch",
            "program": "dotnet",
            "args": ["test"],
            "cwd": "${workspaceFolder}/Tests",
            "console": "integratedTerminal"
        }
    ]
}

by this configuration you can build and test by pressing F5.