【问题标题】:Why is the command 'add-migration' not accepting my installed packages in project.json?为什么命令 'add-migration' 不接受我在 project.json 中安装的包?
【发布时间】:2016-11-18 16:18:49
【问题描述】:

安装 microsoft.entityframework.tools -Pre/ 和 microsoft.entityframework.sqlserver 后,在使用 add-migration "InitialCreate" 时,出现“构建失败”的错误。即使尝试显式构建项目,它也会失败。

这是错误:

1>------ Build started: Project: OdeToFood, Configuration: Debug Any CPU ------
1>  C:\Program Files\dotnet\dotnet.exe build "C:\Users\Nazaqat\Documents\Visual Studio 2015\Projects\OdeToFood\src\OdeToFood" --configuration Debug --no-dependencies
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(262,5): error : 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 causes:
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(262,5): error : 1. The project has not been restored or restore failed - run `dotnet restore`
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(262,5): error : 2. The project does not list one of 'win10-x64, win81-x64, win8-x64, win7-x64' in the 'runtimes' section.
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(262,5): error : 3. You may be trying to publish a library, which is not supported. Use `dotnet pack` to distribute libraries.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我的Project.json 文件如下所示:

{

  "dependencies": {
    "Microsoft.AspNetCore.Diagnostics": "1.1.0",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.EntityFrameworkCore": "1.1.0",
    "Microsoft.EntityFrameworkCore.Design": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.NETCore.App": "1.1.0"
  },

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

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

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

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

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  },

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

在网上看了下,看到一个解决方案,就是在project.json文件中加入如下runtime部分——这样解决方案就构建成功了:

"runtimes": {
    "win10-x64": { }
  }

但是,在包管理器控制台中使用 'add migration "InitialCreate"' 时,我收到错误消息:

Cannot execute this command because Microsoft.EntityFrameworkCore.Design is not installed. Install the version of that package that matches the installed version of Microsoft.EntityFrameworkCore and try again. 

即使我在上述project.json 文件中已经安装了所有软件包。

【问题讨论】:

    标签: c# asp.net json entity-framework entity-framework-core


    【解决方案1】:

    我的 JSON 文件更改为下面的一个,使我的应用程序正常工作。我必须确保我拥有以下安装版本:

    {
      "dependencies": {
    
        "Microsoft.AspNetCore.Diagnostics": "1.1.0",
        "Microsoft.AspNetCore.Mvc": "1.1.0",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
        "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
        "Microsoft.AspNetCore.StaticFiles": "1.1.0",
        "Microsoft.EntityFrameworkCore": "1.1.0",
        "Microsoft.EntityFrameworkCore.Design": "1.1.0",
        "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
        "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
        "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
        "Microsoft.Extensions.Configuration.Json": "1.1.0",
        "Microsoft.Extensions.Logging.Console": "1.1.0",
        "Microsoft.Extensions.Logging.Debug": "1.0.0",
        "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        },
        "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final",
        "Microsoft.AspNetCore.Razor.Tools": {
          "version": "1.0.0-preview2-final",
          "type": "build"
        }
        },
    
    
    
      "tools": {
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
        "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final",
        "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final"
      },
    
      "frameworks": {
        "netcoreapp1.0": {
          "imports": [
            "dotnet5.6",
            "portable-net45+win8"
          ]
        }
      },
    
    
      "buildOptions": {
        "emitEntryPoint": true,
        "preserveCompilationContext": true
      },
    
      "runtimeOptions": {
        "configProperties": {
          "System.GC.Server": true
        }
      },
    
      "publishOptions": {
        "include": [
          "wwwroot",
          "web.config"
        ]
      },
    
      "scripts": {
        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
      }
    }
    

    【讨论】:

    • 对于那些想知道有什么不同的人,将"type": "platform" 添加到Microsoft.NETCore.App 是您正在寻找的解决方法。
    【解决方案2】:

    您还需要更新frameworks 部分以定位netcoreapp1.1

    如果这不能帮助替换它:

    "frameworks": {
      "netcoreapp1.1": {
        "dependencies": {
          "Microsoft.NETCore.App": {
            "type": "platform",
            "version": "1.1.0"
          }
        },
        "imports": "dnxcore50"
      }
    }
    

    【讨论】:

    • 我把框架1.0改成了1.1,结果是这样的:The specified deps.json [C:\Users\Nazaqat\Documents\Visual Studio 2015\Projects\OdeToFood\src\OdeToFood\bin\Debug\netcoreapp1.1\OdeToFood.deps.json] does not exist,报错信息是:Process finished with non-zero exit code
    • 你清理了项目然后恢复了 NuGet 包吗?
    • 它给出了这个错误install-package : Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 1.1.0-preview4-final' uses features that are not supported by the current version of NuGet. To upgrade NuGet, see http://docs.nuget.org/consume/installing-nuget.,即使我已经有了它。
    • 尝试重新安装 NuGet 扩展。还可以尝试将项目移动到路径中不包含空格或破折号的文件夹
    • @AndriySvyryd 文件位于 Debug\netcoreapp1.1\win10-x64 位置,这就是问题所在。也有同样的问题。如何解决?
    猜你喜欢
    • 2017-04-03
    • 2020-11-13
    • 2020-02-26
    • 1970-01-01
    • 2018-09-01
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 2021-09-03
    相关资源
    最近更新 更多