【问题标题】:Trouble building self contained .NetCore App构建自包含的 .NetCore 应用程序时遇到问题
【发布时间】:2017-02-23 09:34:26
【问题描述】:

所以我正在尝试构建一个自包含的 .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

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

感谢任何帮助。

【问题讨论】:

    标签: c# command-line-interface .net-core self-contained


    【解决方案1】:

    我认为您需要将 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 和此出色的answer 上找到有关自包含部署 (SCD) 的更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-04
      • 1970-01-01
      • 1970-01-01
      • 2019-10-30
      • 2012-09-10
      • 2014-02-19
      • 1970-01-01
      • 2020-08-12
      相关资源
      最近更新 更多