.NET 平台 5.4 库中的 AutoMapper NU1001 fx/ 依赖错误

AutoMapper NU1001 fx/ dependency errors in a .NET Platform 5.4 Library

我是使用 ASP.NET 5 (ASP.NET Core) 的新开发人员。在 VS2015 中,我创建了一个针对 .NET Platform 5.4 (dotnet5.4) 的新 class 库项目,并添加了 AutoMapper NuGet 包,版本 4.2.0。

我收到以下错误,主要针对所有系统包:

3>C:\Users\Andrew\OneDrive\Development\Visual Studio\APT\src\Fideles.Service\project.json : .NET Platform 5.4 error NU1001: The dependency fx/Microsoft.CSharp could not be resolved. 3>C:\Users\Andrew\OneDrive\Development\Visual Studio\APT\src\Fideles.Service\project.json : .NET Platform 5.4 error NU1001: The dependency fx/System.Collections could not be resolved. 3>C:\Users\Andrew\OneDrive\Development\Visual Studio\APT\src\Fideles.Service\project.json : .NET Platform 5.4 error NU1001: The dependency fx/System.Collections.Concurrent could not be resolved.

不过我觉得根据NuGet包的描述应该是支持的: https://www.nuget.org/packages/AutoMapper/

从截图中可以看出,这些包似乎被引用了两次;一次正确,一次错误,带有 fx/ 前缀:

这是我的 project.json:

{
  "version": "1.0.0-*",
  "description": "Fideles.Services Class Library",
  "authors": [ "Andrew" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "frameworks": {
    "dotnet5.4": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-*",
        "System.Collections": "4.0.11-beta-*",
        "System.Linq": "4.0.1-beta-*",
        "System.Runtime": "4.0.21-beta-*",
        "System.Threading": "4.0.11-beta-*"
      }
    }
  },
  "dependencies": {
    "AutoMapper": "4.2.0",
    "Fideles.Common": "1.0.0-*",
    "Fideles.Data": "1.0.0-*"
  }
}

有什么想法吗?谢谢!

问题是 AutoMapper 4.2.0 的 dotnet5.4 isn't supported。根据您的目标,可以将 dotnet5.4 更改为其他内容(例如 dnxcore50)。

我自己的一些库也有同样的问题,我正在等待 netstandard 解决所有这些问题。

如果您不介意中断您的 Visual Studio 工作流程,您可以通过执行以下操作来构建您的应用程序。

  1. 确保安装了新的 dotnet CLI (https://dotnet.github.io/getting-started/)
  2. 运行 dotnet restore 从项目文件夹中的命令行

这解决了构建错误。然后我删除了我的锁定文件并 运行 清理并重建解决方案以取得良好的效果。