2016-09-27 148 views
2

如果我使用Visual Studio 2015 Update 3创建新的ASP.NET Core MVC应用程序,它运行得很好。不过,如果我走说应用程序和更新它的NuGet包ASP.NET核心1.0.1,我得到以下编译错误: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安装。

+1

您是否安装了.NET Core 1.0.1 SDK? – Tseng

+0

另外,请尝试在您的project.json所在的文件夹中运行'dotnet restore'命令。 – Ignas

+0

@Tseng:是的,我已经安装了它。 – kettch

回答

3

我认为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和编译器在抱怨它。

让我知道这是否工作!

+0

好的。这是正确的模式。我已经看到了一些对运行时对象的引用,但从来没有在整个文件的上下文中。有一次,我看到它,它嵌入在框架下。也许这适用于较早的版本。无论如何,谢谢! – kettch

+1

@kettch:请查阅http://schemastore.org/json/了解可用的模式。 Project.json以及其他基于json的配置都在其模式中列出。最近的project.json位于这里:http://json.schemastore.org/project – Tseng

+0

@Tseng酷资源。谢谢! – kettch

5

根据https://github.com/dotnet/core/issues/267: 使用nuget进行更新时,“类型”:“平台”被删除,这有效地将项目更改为独立,因此将强制执行运行时段的要求。

对于我手动添加“type”:“platform”到project.json文件解决了这个问题。

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

而且还acoording https://github.com/dotnet/core/issues/267: 通过的NuGet UI更新调用到项目系统更新project.json,“类型”:“平台”是编辑过程中被删除。 NuGet 3.5.0 RTM(尚未发布)将解决此问题。