2

dotnet new xunit -> dotnet restore -> dotnet test

Total tests: 1. Passed: 1. Failed: 0. Skipped: 0. Test Run Successful. Test execution time: 1,7148 Seconds.

.csproj; change target framework to net461:

  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

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

</Project>

then dotnet restore -> dotnet test

Starting test execution, please wait...
No test is available in C:\Projects\testing\bin\Debug\net461\testing.dll. Make sure that installed test discoverers & executors, platform & framework version sett
ings are appropriate and try again.

How am I supposed to test net461-projects with xunit? I already have a big project I've upgraded from .NET Core 1.0, and testing worked fine before the upgrade, so changing test framework would require some work.

Update

As it turns out, this is probably not related to xunit and testing - ASP.NET Core projects targeting net461 won't run at all on my machine anymore, neither through VS or from cmd.

The project I am trying to run is an new empty web project from the VS template. The csproj looks like this:

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

  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
    <RuntimeIdentifier>win7-x86</RuntimeIdentifier>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
  </ItemGroup>

</Project>

The error I get is this:

dotnet run

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Hosting, Version=1.1.1.0, Culture=neutral, PublicKeyTo
ken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
   at WebApplication2.Program.Main(String[] args)

I have tried removing all traces of Visual Studio and .NET Core from my machine and reinstalling them, but the error is the same.

7
  • Repeated all listed steps - tests successfully discovered with net461. Check dotnet --version and dotnet output - are you using last/release versions? Check parent folders - maybe you have global.json with sdk redirect to other (older) version... Commented Mar 30, 2017 at 8:31
  • dotnet --info .NET Command Line Tools (1.0.1) Product Information: Version: 1.0.1 Commit SHA-1 hash: 005db40cd1 Runtime Environment: OS Name: Windows OS Version: 6.3.9600 OS Platform: Windows RID: win81-x64 Base Path: C:\Program Files\dotnet\sdk\1.0.1 Commented Mar 30, 2017 at 8:34
  • I forgot to mention; this used to work when I had the old SDKs installed. Trying to fix issues with VS2017 and testing I cleared out all the SDKs and reinstalled the newest one. Commented Mar 30, 2017 at 8:34
  • Ok, test should work (add testclass to question text to be 100% sure). Try to manually remove bin and obj folders (only two files will remain - csproj and cs) and rerun restore/test... Commented Mar 30, 2017 at 8:39
  • xUNIT works fine with the latest versions of the .NET Framework and .NET core. You don't need to change test frameworks. There is a xUNIT example at learn.microsoft.com/en-us/dotnet/articles/core/testing/… . Commented Mar 30, 2017 at 9:22

2 Answers 2

1

There is an issue with runtime identifier inference and how the test sdk works.

Try adding this to your <PropertyGroup> (assuming you're on a 64 bit windows):

<RuntimeIdentifier>win7-x64</RuntimeIdentifier>

you could also add

<OutputType>Exe</OutputType>

which would turn your class library project into an exe but this should work around the issue.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply. I fixed the issue by reinstalling windows, so I won't be able to test your answer.
This worked perfectly for me. Are you able to explain why this combination fixes the issue? I'm using dotnet 2.0.0-preview2-006497 with TargetFramework net461
The RID inference should work on windows (GH issue), the OutputType should be defaulted to exe by the Microsoft.NET.Test.Sdk but the architecture of this is going to change for the upcoming 2.0.0 release (+ test sdk version 15.3)
0

Yeah, I've experienced the same issue. Not sure if Microsoft already has a fix available, but it seems that some packages of ASP.NET Core 1.1.x are targeting NetStandard Library 1.6.1, which is not compatible with .NET Framework... See the matrix on MS website here: https://learn.microsoft.com/en-us/dotnet/articles/standard/library#net-platforms-support

We've decided to stick to ASP.NET Core 1.0.x for now.

1 Comment

Might be so, but it's still really weird that the project runs for the others on the team, and also in production. The old dotnet SDKs are still around there, which could be an explaination, but how can I get my machine back to that state?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.