sdk: Coould not run xunit tests for two frameworks in one project

Steps to reproduce

I have this csproj

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
  <PropertyGroup>
    <TargetFrameworks>net46;netcoreapp1.0</TargetFrameworks>
    <AssemblyName>ProjectName</AssemblyName>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="**\*.cs" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk">
      <Version>1.0.0-alpha-20161104-2</Version>
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Test.Sdk">
      <Version>15.0.0-preview-20161123-03</Version>
    </PackageReference>
    <PackageReference Include="xunit">
      <Version>2.2.0-beta4-build3444</Version>
    </PackageReference>
    <PackageReference Include="xunit.runner.visualstudio">
      <Version>2.2.0-beta4-build1194</Version>
    </PackageReference>
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
    <PackageReference Include="Microsoft.NETCore.App">
      <Version>1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.NETCore.Portable.Compatibility">
      <Version>1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.TestPlatform.TestHost">
      <Version>15.0.0-preview-20161123-03</Version>
    </PackageReference>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Expected behavior

dotnet test --framework net46 dotnet test --framework netcoreapp1.0

Actual behavior

dotnet test --framework net46 - works fine dotnet test --framework netcoreapp1.0 - does not work. I got an error

Starting test execution, please wait...
Error: Could not find testhost.dll for source 'C:\Projects\ProjectName\bin\Debug\netcoreapp1.0\ProjectName.dll'. Make sure test project has a nuget reference of package "microsoft.testplatform.testhost".

Environment data

.NET Command Line Tools (1.0.0-preview4-004123)

Product Information: Version: 1.0.0-preview4-004123 Commit SHA-1 hash: 3a3ab7e0b0

Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\1.0.0-preview4-004123

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 20 (11 by maintainers)

Most upvoted comments

I’ve added these two lines and it started working

<OutputType>Exe</OutputType>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>

As of 87e9815a25a29fbfa8b87b5757bd44075ef6df4a, Microsoft.NET.Test.Sdk can handle OutputType mismatch between netcoreapp and net4x targets. There is no need to specify OutputType in the test project csproj.

Please try build/test with latest dotnet-cli dev build.

For me, <OutputType>Exe</OutputType> also fixed the issue

Migration should add this when migrating a project.json with a testrunner key