2

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>
Athari
  • 33,702
  • 16
  • 105
  • 146
Max
  • 6,821
  • 3
  • 43
  • 59

1 Answers1

1

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.

Community
  • 1
  • 1
VMAtm
  • 27,943
  • 17
  • 79
  • 125
  • I have modified the tag like this `net462;netcoreapp1.1` and now compile and run. I have found the github netstandard link to [netstandard table](https://github.com/dotnet/standard/blob/master/docs/versions.md) but I think there is some confusion in Microsoft. – Max Apr 14 '17 at 08:05
  • xUnit continue to raise the error about cannot find the dll, but if I write a simple console program it run – Max Apr 14 '17 at 08:06
  • I think MS simply waits for a 2.0 version for the standard – VMAtm Apr 14 '17 at 13:41
  • @Max related: http://stackoverflow.com/a/42364427/213550 You have to target multiple networks – VMAtm Apr 19 '17 at 16:27