构建独立的 .NetCore 应用程序时遇到问题

Trouble building self contained .NetCore App

所以我正在尝试构建一个独立的 .NetCore 应用程序,它只是一个简单的默认 hello world 应用程序。

我按照 Scott Hanselman's 示例在谷歌搜索答案后如何创建应用程序。

所以我的 project.json

中有这段代码
{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          //"type": "platform",
          "version": "1.1.0"
        }
      },
      "imports": "dnxcore50",
      "runtimes": {
        "win10-x64": {},
        "osx.10.10-x64": {},
        "ubuntu.14.04-x64": {}
      }
    }
  }
}

如您所见,我已经注释掉了类型行并添加了每个平台的运行时。

但是我一直收到这个错误:

Can not find runtime target for framework '.NETCoreApp,Version=v1.1' compatible with one of the targe
t runtimes: 'osx.10.10-x64'. Possible causes:
1. The project has not been restored or restore failed - run `dotnet restore`
2. The project does not list one of 'osx.10.10-x64' in the 'runtimes' section.
3. You may be trying to publish a library, which is not supported. Use `dotnet pack` to distribute li
braries.

现在我在 运行 上 Mac,但在 ubuntu 上发生了同样的错误,但随后报告了与 ubuntu 相关的错误。

我的 dotNet 版本是 = 1.0.0-preview2-1-003177

我有点卡住了,一切似乎都指向它应该工作的事实,这可能是我忽略的一个明显的事情。

感谢任何帮助。

我认为您需要将 json 的结构更改为:

{
    "version": "1.0.0-*",
    "buildOptions": {
        "debugType": "portable",
        "emitEntryPoint": true
    },
    "dependencies": {},
    "frameworks": {
        "netcoreapp1.1": {
            "dependencies": {
                "Microsoft.NETCore.App": {
                    "version": "1.1.0"
                }
             }
         }
    },
    "runtimes": {
        "win10-x64": {},
        "osx.10.10-x64": {},
        "ubuntu.14.04-x64": {}
    }
}

最大的区别是 runtimes 部分 不在 framework 部分中。

请务必在更改 project.json 后 运行 一个 dotnet restore --no-cache

您可以在此 page and with this excellent

上找到有关独立部署 (SCD) 的更多信息