VS2017 为多个框架目标创建一个库

VS2017 create a lib for multiple framework targets

我有一个简单的 Dll,我在其中定义了一些 class,如下所示:

public class Parameters 
{
    public string Message { get; set; }
}

我添加了一个 NuGet 包 Newtonsoft.Json

此 DLL 必须由 netcoreapp1.1net462.

使用

我已经尝试修改 csproj 并添加了这个

<TargetFramework>netstandard1.5</TargetFramework>

如果我启动 dotnet build,dll 已成功构建,但我无法使用来自 netcore 应用程序的 DLL,也无法来自 net462

特别是如果我添加一个 xUnit 测试并在 DLL 中引用一个 class 它会引发错误:

System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.1.0.0 [..]

任何人都可以向我解释 net462netcoreappnetstandard1.5 目标框架是如何工作的?以及如何构建一个dll跨框架?

更新

要找到相关程序集,必须在 xunit .csproj 中添加以下代码

<OutputType>Exe</OutputType>

您可以找到 table .Net Standard 平台支持 here。您需要了解 .Net Standard 不是 不是 框架,它是图书馆实施 .Net Standard 支持的规则。

因此,如果您需要您的库同时支持 .Net Core.Net Framework 4.6,您可以 , not 1.5 or 1.6, and .Net Framework, according to this blog(注意标签的复数形式)。

<TargetFrameworks>netstandard1.6.1;net462</TargetFrameworks>

也许没有 net462 也能正常工作,因为它应该支持 1.6 版本,我稍后会为此更新。

我还发现 xUnit 博客 post 关于 running tests against multiple targets,他们使用了这个:

<PropertyGroup>
  <TargetFrameworks>net452;netcoreapp1.1</TargetFrameworks>
</PropertyGroup>

请注意,他们针对的是 netcoreapp,而不是 netstandard