'dotnet publish' 在不存在的 lib 目录中引用依赖项时出错

'dotnet publish' error referencing dependencies in non-existent lib directory

我正在尝试通过 Travis CI 将 dotnet 核心 Web 应用程序部署到 Ubuntu VPS。我正在使用 dotnet restore && dotnet publish -c release -r ubuntu.16.04-x64 在 scp-ing 到服务器之前进行构建。构建和部署在 Travis 上完成得很好,但是当我在我的服务器上重新启动应用程序服务时,出现如下错误。

Error: assembly specified in the dependencies manifest was not found -- package: 'microsoft.aspnetcore.antiforgery', version: '1.1.1', path: 'lib/netstandard1.3/Microsoft.AspNetCore.Antiforgery.dll'

作为发布的一部分创建的 *.deps.json 文件包含如下行。

"microsoft.aspnetcore.antiforgery/1.1.1": {
    "dependencies": {
      "Microsoft.AspNetCore.DataProtection": "1.1.1",
      "Microsoft.AspNetCore.Http.Abstractions": "1.1.1",
      "Microsoft.AspNetCore.Http.Extensions": "1.1.1",
      "Microsoft.AspNetCore.WebUtilities": "1.1.1",
      "Microsoft.Extensions.ObjectPool": "1.1.0",
      "NETStandard.Library": "1.6.1"
    },
    "compile": {
      "lib/netstandard1.3/Microsoft.AspNetCore.Antiforgery.dll": {}
    }
  },
  "microsoft.aspnetcore.authorization/1.1.1": {
    "dependencies": {
      "Microsoft.Extensions.Logging.Abstractions": "1.1.1",
      "Microsoft.Extensions.Options": "1.1.1",
      "NETStandard.Library": "1.6.1",
      "System.Security.Claims": "4.3.0"
    },
    "compile": {
      "lib/netstandard1.3/Microsoft.AspNetCore.Authorization.dll": {}
    }
},

那些 "compile" 属性是导致问题的原因,因为如果我手动删除 lib/netstandard1.3/Microsoft.AspNetCore.Antiforgery.dll 的编译属性,错误现在变为:

Error: assembly specified in the dependencies manifest was not found -- package: 'microsoft.aspnetcore.authorization', version: '1.1.1', path: 'lib/netstandard1.3/Microsoft.AspNetCore.Authorization.dll'

为什么要在 *.deps.json 文件中创建这些编译属性?他们需要吗?如果是这样,为什么我 dotnet publish 时没有创建 lib 目录?如果没有,我如何删除它们以便我的应用程序运行?

谢谢。

所以,我再次阅读 docs 并注意到一个我一直忽略的小细节。我一直在部署 netcoreapp1.1 的所有内容,而不仅仅是 netcoreapp1.1/publish 的内容。因此,我的服务器正在执行 netcoreapp1.1 中的 .dll 而不是 netcoreapp1.1/publish 中的那个。这解决了我所有的问题。