I am running .NET Framework 4.6.1
to build a test class library where I build MSTest
tests (Microsoft.VisualStudio.TestTools.UnitTesting
). I can run the tests absolutely fine by going into the folder containing the test project and running dotnet test
.
However, VS does NOT discover the tests in the Text Explorer. I have updated every single related NuGet package to latest as recommended in some answer to this problem:
I have also tried both Test -> Test Settings -> Default Processor Architecture -> x86
and x64
.
I always get the following error:
[1/10/2018 5:01:03 PM Warning] Test run will use DLL(s) built for framework Framework45 and platform X86. Following DLL(s) will not be part of run:
What can cause this? If it helps, all my co-workers have the same issue, and only on this solution.
This is a Microsoft.AspNetCore 1.1.2
project.
Edit: csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CsvHelper" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="Microsoft.VisualStudio.TestPlatform" Version="14.0.0.1" />
<PackageReference Include="Moq" Version="4.7.99" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CommonHelpers\CommonTestHelpers.csproj" />
<ProjectReference Include="..\ks-systems\ks-systems.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>
Edit 2:
Looks like changing to x86
/ x64
in the menu bar doesn't change my .csproj
. I changed it by hand to x86
- this got them discovered. Now all 56 tests are failing with the following:
Message: Unable to create instance of class cm-tools.Tests.Services.TripScholarshipServiceTest. Error: System.BadImageFormatException: Could not load file or assembly 'CtsPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format..
Note that making the change above causes the tests to be discovered, and also causes all of them to FAIL, including when trying dotnet test
from console, which works without the change.