【问题标题】:ASP.NET Core 1.0.1 breaks projectsASP.NET Core 1.0.1 打破了项目
【发布时间】:2016-10-06 15:38:23
【问题描述】:

如果我使用 Visual Studio 2015 Update 3 创建一个新的 ASP.NET Core MVC 应用程序,它运行得很好。但是,如果我使用该应用程序并将其 Nuget 包更新到 ASP.NET Core 1.0.1,我会收到以下构建错误:

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

这是一个错误,还是环境问题?

附录:

恢复的日志看起来不错:

log  : Restoring packages for <path to project>\project.json...
log  : Restoring packages for tool 'Microsoft.AspNetCore.Server.IISIntegration.Tools' in E:\Software Projects\subq\src\SubQ.API\project.json...
log  : Lock file has not changed. Skipping lock file write. Path: <path to project>\project.lock.json
log  : <path to project>\project.json
log  : Restore completed in 6210ms.

project.json 看起来像这样:

{
    "dependencies": {
        "Microsoft.AspNetCore.Mvc": "1.0.1",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
        "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
        "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
        "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
        "Microsoft.Extensions.Configuration.Json": "1.0.0",
        "Microsoft.Extensions.Logging": "1.0.0",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "Microsoft.Extensions.Logging.Debug": "1.0.0",
        "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
        "Microsoft.NETCore.App": "1.0.1"
    },

    "tools": {
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
    },

    "frameworks": {
        "netcoreapp1.0": {
            "imports": [
                "dotnet5.6",
                "portable-net45+win8"
            ],
            "runtimes": {
                "win10-x64": {}
            }
        }
    },

    "buildOptions": {
        "emitEntryPoint": true,
        "preserveCompilationContext": true
    },

    "runtimeOptions": {
        "configProperties": {
            "System.GC.Server": true
        }
    },

    "publishOptions": {
        "include": [
            "wwwroot",
            "Views",
            "Areas/**/Views",
            "appsettings.json",
            "web.config"
        ]
    },

    "scripts": {
        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
    }
}

已安装最新的 SDK。

【问题讨论】:

  • 您是否安装了 .NET Core 1.0.1 SDK?
  • 另外,尝试在 project.json 所在的文件夹中运行dotnet restore 命令。
  • @Tseng:是的,我已经安装好了。
  • @Ignas:是的。 Visual Studio 在构建期间运行还原,我已从命令行手动运行它。

标签: asp.net-core


【解决方案1】:

根据https://github.com/dotnet/core/issues/267: 使用 nuget 更新时,“type”:“platform” 被删除,这实际上将项目更改为独立项目,因此会强制要求运行时部分。

对我来说,手动添加 "type" : "platform" 到 project.json 文件解决了这个问题。

    "dependencies": {
       "Microsoft.NETCore.App": {
          "version": "1.0.1",
          "type": "platform"
        },

还与https://github.com/dotnet/core/issues/267 合作: 通过 NuGet UI 调用更新到项目系统以更新 project.json,“type”:“platform”在该编辑期间被删除。 NuGet 3.5.0 RTM(尚未发布)将提供解决此问题的方法。

【讨论】:

    【解决方案2】:

    我认为runtimes 应该放在frameworks 设置之外。改变

    "frameworks": {
        "netcoreapp1.0": {
            "imports": [
                "dotnet5.6",
                "portable-net45+win8"
            ],
            "runtimes": {
                "win10-x64": {}
            }
        }
    },
    

    "frameworks": {
        "netcoreapp1.0": {
            "imports": [
                "dotnet5.6",
                "portable-net45+win8"
            ]
        }
    },  
    "runtimes": {
        "win10-x64": {},
        "win81-x64": {}
    },
    

    我还必须添加 win81-x64,因为我在 Windows 8.1 上运行,编译器对此表示抱怨。

    让我知道这是否有效!

    【讨论】:

    • 好的。那是正确的架构。我已经看到了一些对运行时对象的引用,但从未在整个文件的上下文中看到。有一次我确实看到它,它嵌入在框架下。也许这适用于早期版本。无论如何,谢谢!
    • @kettch:请咨询schemastore.org/json 了解可用的架构。 Project.json 以及其他基于 json 的配置都在其架构中列出。最新的 project.json 位于此处:json.schemastore.org/project
    • @Tseng 酷资源。谢谢!
    猜你喜欢
    • 2022-01-20
    • 2017-04-12
    • 2012-10-20
    • 2017-02-25
    • 1970-01-01
    • 2020-07-01
    • 2017-03-07
    • 1970-01-01
    • 2021-10-17
    相关资源
    最近更新 更多