I have a .Net Core API project. It must use some 3rd party library for .Net Framework (not compatible with net core) so we have changed in the .csproj the TargetFramework property from "netcoreapp2.0" to "net47":
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<!-- <TargetFramework>netcoreapp2.0</TargetFramework> -->
<TargetFramework>net47</TargetFramework>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
```
Everything is working fine apart from the fact that I'm not able to create test projects on this.
I like to use NUnit.
I tried to create .net core test project (using both MS Unit Test and XUnit) but them are both unable to run the test.
"Run test" is simply ignored.
I created also a .Net Framework test project and in this case I have an error at runtime when the test try to use some classes from the "fake" .Net Core project.
The error is this:
Message: System.BadImageFormatException : Could not load file or assembly 'MyCompany.ProjectA.Api, 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.
Another developer that use ReSharper can run the test created with .Net Core without any problem.
It is discovered (using ReSharper) and it can be debugged.
Please do not suggest me to NOT use "net47" in the project file. It is not an option.
Additional info.
The test project is loading the correct packages:
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
<PackageReference Include="NUnit" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
same problem (test dot discovered or ignored on "run") adding these:
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
When the test is ignored the error in the console is this:
[19/02/2018 16:01:28 Warning] Exception System.InvalidOperationException, Exception thrown executing tests in D:\Data\GIT\MyCompany.ProjectA.UnitTests.API_2\bin\Debug\net47\MyCompany.ProjectA.API.dll
[19/02/2018 16:01:28 Warning] Operation is not valid due to the current state of the object.
[19/02/2018 16:01:28 Warning] at Mono.Cecil.ModuleDefinition.ProcessDebugHeader()
at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader)
at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters)
at Mono.Cecil.ModuleReader.CreateModuleFrom(Image image, ReaderParameters parameters)
at Mono.Cecil.ModuleDefinition.ReadModule(Stream stream, ReaderParameters parameters)
at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
at NUnit.VisualStudio.TestAdapter.NavigationDataProvider.CacheNewTypes(String assemblyPath, IDictionary`2 types) in C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NavigationDataProvider.cs:line 103
at NUnit.VisualStudio.TestAdapter.NavigationDataProvider.GetNavigationData(String className, String methodName) in C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NavigationDataProvider.cs:line 48
at NUnit.VisualStudio.TestAdapter.TestConverter.MakeTestCaseFromXmlNode(XmlNode testNode) in C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\TestConverter.cs:line 144
at NUnit.VisualStudio.TestAdapter.TestConverter.ConvertTestCase(XmlNode testNode) in C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\TestConverter.cs:line 79
at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunAssembly(String assemblyPath, TestFilter filter) in C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 249
[Solution]
I've removed the RID from the API project and the is found and run.
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
I tried to change it to "win-x86" or to change the test project from non-selection (= any CPU) to x86 or x64.
None of these is a good solution.