Reputation: 7110
I have a simple Dll where I defined some class like this:
public class Parameters
{
public string Message { get; set; }
}
I added a NuGet package Newtonsoft.Json
.
This DLL MUST be consumed by a netcoreapp1.1 and a net462.
I have tried to modify the csproj and added this
<TargetFramework>netstandard1.5</TargetFramework>
If I launch dotnet build the dll was build successfully but I cannot consume the DLL from the netcore app neither from net462
In particular if I add a xUnit
test and reference a class inside the DLL it raise the error:
System.IO.FileLoadException
: Could not load file or assembly 'System.Runtime, Version=4.1.0.0 [..]
Anybody can explain me how work net462
, netcoreapp
and netstandard1.5
target frameworks? And how build a dll cross framework?
UPDATE
For find the related assembly must be add the code below on xunit .csproj
<OutputType>Exe</OutputType>
Upvotes: 2
Views: 598
Reputation: 28366
You can find a table for .Net Standard
platforms support here. You need to understand that .Net Standard
is not a framework, it's a rules for libraries to implement for .Net Standard
support.
So, if you need your library to support both .Net Core
and .Net Framework
4.6, you need to target .Net Standard
1.6.1 (!), not 1.5 or 1.6, and .Net Framework
, according to this blog (note plural form of tag).
<TargetFrameworks>netstandard1.6.1;net462</TargetFrameworks>
Maybe it will work without the net462
, as it should support 1.6 version, I'll update later for this.
Also I found xUnit
blog post about running tests against multiple targets, they used this:
<PropertyGroup>
<TargetFrameworks>net452;netcoreapp1.1</TargetFrameworks>
</PropertyGroup>
Note that they've targeted the netcoreapp
, not the netstandard
.
Upvotes: 1