The term “Add-Migration” is not recognized

后端 未结 18 2155
情深已故
情深已故 2020-12-07 23:51

I\'m using this MSDN Tutorial to run in VS2015 the command PM> Add-Migration MyFirstMigration -context BloggingContext that ran yesterday successfully but to

相关标签:
18条回答
  • 2020-12-08 00:15

    I think the answer needs updating in 2017, as MS have made some (breaking) changes that is detailed here.

    https://github.com/aspnet/EntityFramework/issues/7053

    To summarise, you will now need a reference to EntityFrameWorkCore.Tools.DotNet in the Tools Section as below

    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0"

    I have also posted a working project.json file below in case some one runs in problems.

    {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.1",
          "type": "platform"
        },
        "Microsoft.AspNetCore.Diagnostics": "1.0.0",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "Microsoft.AspNetCore.Razor.Tools": {
          "version": "1.0.0-preview2-final",
          "type": "build"
        },
        "Microsoft.AspNetCore.StaticFiles": "1.0.0",
        "Microsoft.AspNetCore.Mvc": "1.0.1",
        "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
        "Microsoft.Extensions.Configuration.Json": "1.0.1",
        "Microsoft.EntityFrameworkCore.Tools": {
          "version": "1.0.0-preview2-final",
          "type": "build"
        }
      },
    
      "tools": {
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
        "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
        "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0"
      },
    
      "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%" ]
      }
    }
    
    0 讨论(0)
  • 2020-12-08 00:16

    You have to know what is your Entity-Framework version. Also after that you have to check project.json and control these sections:

    In Dependencies

    check:

    Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    

    This section:

    "version": "1.0.0-preview2-final",

    is related with version of your Entity-Framework and you have to change this with that.

    After that the second section of the proj.json is here, In the Tools section of JSON you have:

    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    

    Also this part of code is related with your Entity-Framework and last part of code in Dependencies section.

    Note: After do this issues you should to close CMD and restart visual studio.

    0 讨论(0)
  • 2020-12-08 00:17

    I had this problem in Visual Studio 2013. I reinstalled NuGet Package Manager:

    https://marketplace.visualstudio.com/items?itemName=NuGetTeam.NuGetPackageManagerforVisualStudio2013

    0 讨论(0)
  • 2020-12-08 00:18

    I had the same problem and found that it was a Visual Studio versioning problem in the Solution file.

    I was targeting:

    VisualStudioVersion = 14.0.25123.0

    But I needed to target:

    VisualStudioVersion = 14.0.25420.1

    After making that change directly to the Solution file, EF Core cmdlets started working in the Package Manager Console.

    0 讨论(0)
  • 2020-12-08 00:18

    This is what worked for me: From Visual Studio click on

    Tools --> NuGet Package Manager --> Package Manager Console

    Then you can run Add-Migration, for example:

    Add-Migration InitialCreate
    
    0 讨论(0)
  • 2020-12-08 00:19

    Ensure Microsoft.EntityFrameworkCore.Tools is referenced in the dependencies section of your project.json. NuGet won't load the Package Manager Commands from the tools section. (See NuGet/Home#3023)

    {
      "dependencies": {
        "Microsoft.EntityFrameworkCore.Tools": {
          "version": "1.0.0-preview2-final",
          "type": "build"
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题