3

I am trying to create my first migration of an ASP.Net Core project I am developing in Visual Studio 2015. My Solution only has the one Project. My project.json file resides in the root of my Project folder.

I right-click on the Project and select 'Open command line > default' and enter the following:

dotnet ef migrations add InitialDatabase

The command line returns:

No project was found. Change the current working directory or use the --project option.

I have tried all different versions of EntityFrameworkCore and Tools. My project.json file is as follows:

{
  "dependencies": {
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.1",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.1",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.1",
    "Microsoft.EntityFrameworkCore": "1.0.2",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.2",
    "Microsoft.EntityFrameworkCore.Design": {
      "type": "build",
      "version": "1.0.2" 
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "type": "build",
      "version": "1.0.0-msbuild3-final"
    },
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-msbuild3-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.1",
    "Microsoft.Extensions.Logging.Console": "1.0.1",
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.1"
    }
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-msbuild3-final",
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-msbuild3-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%" ]
  }
}

Any advice would be extremely welcome. Thanks.

TDC
  • 1,869
  • 3
  • 25
  • 40
  • Point to the directory which has project.json and execute the command. I think you are in parent folder (one level up)currently. – Developer Jan 31 '17 at 17:33
  • Try this for us: in VS, open the Package Manager Console (if you dont see it, go to `View -> Other Windows -> Package Manager Console`). In the PMC, call `Add-Migration {YourMigrationNameHere}`. – steamrolla Feb 01 '17 at 14:40
  • I think that using add-migration in the package manager has been deprecated now. – TDC Feb 01 '17 at 18:33

2 Answers2

5
"tools": {
  "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-msbuild3-final"
}

Version 1.0.0-msbuild3-final only works with the new, MSBuild-based projects (not project.json). Use version 1.0.0-preview3-final instead.

bricelam
  • 28,825
  • 9
  • 92
  • 117
  • Good advice @bricelam. By chance, last night I tried using the following combination: `"Microsoft.EntityFrameworkCore": "1.0.2"`, `"Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final"`, `"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"`, `"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-msbuild3-final"` and it worked. As a developer new to ASP.Net Core it's very difficult to find the right combination of packages which work together in harmony. Should I try `1.0.0-preview3-final`? – TDC Feb 01 '17 at 18:31
  • 1
    The tooling story has been a bit chaotic with the switch from `project.json` to MSBuild. When the tools finally RTM (with VS 2017), the story for EF at least will be to make sure all the major and minor version numbers alight (e.g. either 1.0 or 1.1, but not mixed) There are efforts going on to simplify how you get a single, coherent set of .NET Core packages... – bricelam Feb 02 '17 at 17:08
  • Good to know. Like many, I'm sure, I look forward to it settling down. – TDC Feb 03 '17 at 13:17
  • if this is the answer then you can accept it no? @TDC – Sampath Feb 05 '17 at 14:24
  • I would, but @bricelam suggested I use version `1.0.0-preview3-final` and I found that by using `1.0.0-preview2-final` everything worked. I don't actually know if the suggested version would fix my problem, much as I would like to mark it as correct. A moral dilemma! – TDC Feb 05 '17 at 16:22
-1

The dotnet-ef command has moved.

You will need to add a reference to Microsoft.EntityFrameworkCore.Tools.DotNet AND Microsoft.EntityFrameworkCore.Design to your dependencies in project.json, then add Microsoft.EntityFrameworkCore.Tools.DotNet to the tools section and you should be good to go.

Cited from: http://errummwelluhh.blogspot.com. I have also posted the same answer for the same question here.

Community
  • 1
  • 1
susieloo_
  • 1,391
  • 1
  • 16
  • 22