IEnumerable<>;在未被引用的程序集中定义-新的NuGet类库项目

本文关键字:定义 集中 程序集 NuGet 项目 类库 程序 新的 gt lt 引用 | 更新日期: 2023-09-27 18:23:37

我使用的是VS2015 Community,我安装了.NET 4.6.01040,并按照这些说明安装了ASP.NET 5。

我想开始将一个站点从MVC5迁移到MVC6,以及它附带的所有其他更新,所以我从保存我的数据模型的实体类库项目开始。这就是我的project.json文件的样子:

{
  "version": "1.0.0-*",
  "description": "test.Entities Class Library",
  "authors": [ "me" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "frameworks": {
    "net461": {
      "dependencies": { "System.Runtime": "4.0.0.0" }
    },
    "dotnet5.4": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Linq": "4.0.1-beta-23516"
        "System.Collections": "4.0.11-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
      }
    }
},
  "dependencies": {
    "EntityFramework.Core": "7.0.0-rc1-final",
  }
}

我将框架类型从"net451"更改为"net461",因为我认为这就是问题所在,我还尝试添加对依赖项的引用,但没有成功。。。

错误发生在这里:

[NotMapped]
public decimal TotalOrders => Math.Round(Orders.Where(x => x.Code.StartsWith("5")
                             .Sum(x => x.Amount),MidpointRounding.AwayFromZero);

完整错误为:

CS0012  The type 'IEnumerable<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.    test.Entity..NET Framework 4.6

你知道如何在新的项目类型中实现这一点吗?

IEnumerable<>;在未被引用的程序集中定义-新的NuGet类库项目

因为我从答案中不清楚需要什么,所以我将在这里提供。。。。

{
  "version": "1.0.0-*",
  "description": "test.Entities Class Library",
  "authors": [ "me" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "frameworks": {
      "net461": {
      "dependencies": { "System.Runtime": "4.0.0.0" },
      "frameworkAssemblies": {
         "System.Runtime": "4.0.10.0"
      }
    },
    "dotnet5.4": {
       "dependencies": {
       "Microsoft.CSharp": "4.0.1-beta-23516",
       "System.Runtime": "4.0.21-beta-23516",
       "System.Linq": "4.0.1-beta-23516"
       "System.Collections": "4.0.11-beta-23516",
       "System.Threading": "4.0.11-beta-23516"
     }
   }
  },
   "dependencies": {
    "EntityFramework.Core": "7.0.0-rc1-final",
  }
}

net461目标框架名称(TFM)表示完整的桌面.NET框架,如果要从此框架引用System.Runtime,则需要将"System.Runtime": "4.0.0.0"条目移动到frameworkAssemblies节点。