aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

The term 'add-migration' is not recognized as the name of a cmdlet

Open dvdobrovolskiy opened this issue 10 years ago • 23 comments

It getting very annoying and I dunno so far what cases what but: every time I close Visual Studio 2015 and restart it opening same project again I can`t add migration with error

add-migration : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operab le program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again . At line:1 char:1

  • add-migration 16072016
  • - CategoryInfo          : ObjectNotFound: (add-migration:String) [], CommandNotFoundException
    - FullyQualifiedErrorId : CommandNotFoundException
    
    

I have in tools "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",

and in dependencies "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", "Microsoft.EntityFrameworkCore.Tools": { "version": "1.0.0-preview2-final",

It every time.

dvdobrovolskiy avatar Jul 16 '16 14:07 dvdobrovolskiy

Found

1 down vote

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.

dvdobrovolskiy avatar Jul 16 '16 14:07 dvdobrovolskiy

No, problem still exi

dvdobrovolskiy avatar Jul 26 '16 09:07 dvdobrovolskiy

Opening this issue again 'add-migration' is not recognized as the name of a cmdlet is a very annoying bug and I facing it once in a day or two. And I still do not understand what causes this issue. Some random play with reopening studio and other things suddenly resoles issue but I cannot catch what exactly.

PS VisualStudioVersion = 14.0.25431.01 - same as studio

error itself

add-migration : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

  • add-migration
  • - CategoryInfo          : ObjectNotFound: (add-migration:String) [], CommandNotFoundException
    - FullyQualifiedErrorId : CommandNotFoundException
    

dvdobrovolskiy avatar Oct 08 '16 23:10 dvdobrovolskiy

Today again

add-migration : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelli ng of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

  • add-migration
  • - CategoryInfo          : ObjectNotFound: (add-migration:String) [], CommandNotFoundException
    - FullyQualifiedErrorId : CommandNotFoundException
    

dvdobrovolskiy avatar Oct 12 '16 20:10 dvdobrovolskiy

Now again. So frustrating. Happens once I restart comp. As I do it not often (usually sent it to hibernation) with error coming again I forgetting how I solved it. Every time it just standard restart reset clean project rebuild all things.

PM> add-migration jobs -Verbose add-migration : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or opera ble program. Check the spelling of the name, or if a path was included, verify that the path is correct and try aga in. At line:1 char:1

  • add-migration jobs -Verbose
  • - CategoryInfo          : ObjectNotFound: (add-migration:String) [], CommandNotFoundException
    - FullyQualifiedErrorId : CommandNotFoundException
    

dvdobrovolskiy avatar Oct 30 '16 17:10 dvdobrovolskiy

And again today. Can somebody kill this issue?

dvdobrovolskiy avatar Nov 20 '16 20:11 dvdobrovolskiy

add-migration : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

  • add-migration
  •   + CategoryInfo          : ObjectNotFound: (add-migration:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    

dvdobrovolskiy avatar Dec 02 '16 17:12 dvdobrovolskiy

Now version in solution file matches studio version. But I cannot made migration

dvdobrovolskiy avatar Dec 02 '16 17:12 dvdobrovolskiy

again today.

So so annoying

add-migration : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check th e spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

  • add-migration usertracking
  •   + CategoryInfo          : ObjectNotFound: (add-migration:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    

dvdobrovolskiy avatar Dec 09 '16 14:12 dvdobrovolskiy

Try the following steps:

  1. Remove all Microsoft.EntityFrameworkCore.Tools references from dependencies and tools sections inside a project.json

  2. Close Package Manager Console (PMC) and restart Visual Studio

  3. Add under dependencies section:

"Microsoft.EntityFrameworkCore.Tools": { "version": "1.0.0-preview2-final", "type": "build" } 4) Add under tools section

"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" 5) Restart again Visual Studio 2015

  1. Open the PMC and type

Add-Migration $Your_First_Migration_Name$ That's because the PMC recognize the tools when Visual Studio is starting.

Padmanaabhah avatar Jun 16 '17 13:06 Padmanaabhah

So I don't have a project.json file, but csproj, and I removed it and added it manually to csproj and that solved my issue, but is this a permanent fix, or will this issue start to come back again, as it has before?

Rudde avatar Jul 06 '17 08:07 Rudde

I commented out the original contents of my .csproj file and pasted the following:

netcoreapp1.0 {yourAssemblyName} {yourAssemblyName} $(PackageTargetFallback);dotnet5.6;portable-net45+win8 false false false
<ItemGroup>
	<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>

Using this code, and restarting VS, Add-Migration {migrationName} works for me now.

amitachawla avatar Jul 06 '17 14:07 amitachawla

netcoreapp1.0 {yourassemblyName} {yourassemblyName} $(PackageTargetFallback);dotnet5.6;portable-net45+win8 false false false

<ItemGroup>
	<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>

new content of .csproj file

amitachawla avatar Jul 06 '17 14:07 amitachawla

If you are interested in knowing how migrations work with .NET Core read this: https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/migrations

I don't think that the original Add-Migration PowerShell scripts are supported with .NET Core.

If you guys have a problem with migrations, please open another issue. This is getting confusing who is answering to what question.

Should this be closed?

cc: @Eilon @rowanmiller

MaximRouiller avatar Jul 06 '17 14:07 MaximRouiller

cc @divega / @ajcvickers / @bricelam

Eilon avatar Jul 06 '17 18:07 Eilon

is this a permanent fix, or will this issue start to come back again

Manually adding the DotNetCliToolReference is the only way to use the package. (until we get NuGet/Home#4190)

I don't think that the original Add-Migration PowerShell scripts are supported with .NET Core.

They are, and they're recommended if you're using Visual Studio since they provide a more integrated experience. (e.g. detecting your startup project, opening newly created files, etc.)

bricelam avatar Jul 06 '17 18:07 bricelam

@bricelam Any possibilities to add them to the doc? I haven't seen them anywhere. :confused:

MaximRouiller avatar Jul 06 '17 18:07 MaximRouiller

They're buried somewhere inside the EF Docs: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell

bricelam avatar Jul 06 '17 18:07 bricelam

Also mentioned in EF's getting started docs. E.g. https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db

bricelam avatar Jul 06 '17 18:07 bricelam

Am also having these issues am using VS 2013 and EF 6,pls help

kansulum avatar Dec 19 '17 15:12 kansulum