为现有的类库添加.net Core支持



我有一个现有的开源库,我已经在。net 4.5中编写,我想从中创建一个NuGet。问题是这个NuGet包只对。net 4.5应用程序可用。

我想做的是在同一个NuGet上同时支持。net 4.5和。net Core(我已经看到了这样做的包JSON.NET) -我怎么能增加对现有NuGet的支持?我如何在一个类库中支持多个。net版本?

您可以继续为net45目标使用csproj并添加项目。以"net45"one_answers"netstandard1"为目标的Json。X"框架(使用project。Json(我的库作为示例):

  "frameworks": {
    "net45": {
      "frameworkAssemblies": {
        "System.Data": "",
        "System.ComponentModel.DataAnnotations" : ""
      },
      "buildOptions": {
        "define": []
      }
    },
    "netstandard1.5": {
      "dependencies": {
        "NETStandard.Library": "1.6.0",
        "System.Data.Common": "4.1.0",
        "System.Reflection": "4.1.0",
        "System.Reflection.Primitives": "4.0.1",
        "System.Threading": "4.0.11",
        "System.Threading.Tasks": "4.0.11",
        "System.ComponentModel.Annotations": "4.1.0" 
      },
      "buildOptions": {
        "define": [ "NET_STANDARD" ]
      }
    }

请注意,您可以为net45或特定于netcore的代码片段定义条件编译常量。

当你有项目。使用以下命令,您可以准备包含net45和netstandard版本的nuget包:

> dotnet pack --configuration Release

不要忘记"dotnet pack"不使用nuspec文件中的信息,所有的元数据都应该出现在project.json中。

最新更新