The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or operable program.

demetsen

Member
Joined
Jan 24, 2022
Messages
14
Programming Experience
1-3
Hi everyone,

I am running PowerShell in C# code and actually it runs properly. But, when I try to do scaffolding it returns this error:
C#:
The term 'Scaffold-DbContext' 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.

The command is:
Scaffold-DbContext \"Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = XE))); User Id = C##DMT;Password=DMT;\" Oracle.EntityFrameworkCore -contextdir Data -OutputDir Models -context ModelContext -Force;

However, when I run the same command in Package Manager console manually, there is no issue at all. This issue is not about what DB type that I use. It can be Oracle or MsSql.

These are packages:
1643098458015.png


Is there something that I am missing?
 
Last edited by a moderator:
I don't think that specific syntax works outside the Package Manager Console. I think you need to use dotnet ef dbcontext scaffold.
Thank you. But I Tried this one too:

dotnet ef dbcontext scaffold "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = XE))); User Id = ***;Password=***;" Oracle.EntityFrameworkCore -contextdir Data -OutputDir Models -context ModelContext

And the error was:

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

I tried cd [project_path] command before I run the scaffold command but it did not worked again.
 
And what error do you get when you use that syntax?
 
And what error do you get when you use that syntax?
syntax:
C#:
"dotnet ef dbcontext scaffold \"Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = XE))); User Id = ***;Password=***;\" Oracle.EntityFrameworkCore -p C:\\Users\\dmt\\source\\repos\\ScaffoldingInCode\\ScaffoldingInCode\\ScaffoldingInCode.csproj -contextdir Data -OutputDir Models -context ModelContext -Force;"

response:
C#:
Build started...
Build failed. Use dotnet build to see the errors.
 
Last edited by a moderator:
And when you followed the explicit instructions in that message you just quoted, what errors did you see?
syntax:
C#:
"dotnet ef dbcontext scaffold \"Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = XE))); User Id = ***;Password=***;\" Oracle.EntityFrameworkCore -p C:\\Users\\dmt\\source\\repos\\ScaffoldingInCode\\ScaffoldingInCode\\ScaffoldingInCode.csproj -contextdir Data -OutputDir Models -context ModelContext -Force;"

response:
C#:
Build started...
Build failed. Use dotnet build to see the errors.
C#:
PM> dotnet build C:\Users\dmt\source\repos\ScaffoldingInCode\ScaffoldingInCode\ScaffoldingInCode.csproj
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  ScaffoldingInCode -> C:\Users\demet.sen\source\repos\ScaffoldingInCode\ScaffoldingInCode\bin\Debug\netcoreapp3.1\ScaffoldingInCode.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.13
 
Last edited by a moderator:
As an aside, for multi-line text that you want mark as code, please use code blocks </> instead of the inline code >_ . ( Yes, we know that the iconography on this site clashes with more other more commonly used icons. )

Anyway, don't run the command in the Package Manager Console. Instead run it in a PowerShell console. Do Start>Run... Powershell.exe for traditional PowerShell, or Start>Run... pwsh.exe for PowerShell Core. (Sorry I'm blanking right now whether that PowerShell hosting that you are doing is using the older PowerShell or the newer PowerShell Core.)
 
The result is the same with the powershell. There are no warnings or errors.

dotnet build:
PS C:\Users\dmt> dotnet build C:\Users\dmt\source\repos\ScaffoldingInCode\ScaffoldingInCode\ScaffoldingInCode.csproj
.NET için Microsoft (R) Build Engine sürüm 17.0.0+c9eb9dd64
Telif Hakki (C) Microsoft Corporation. Tüm haklari saklidir.

  Geri yüklenecek projeler belirleniyor...
  Geri yükleme için tüm projeler güncel.
  ScaffoldingInCode -> C:\Users\dmt\source\repos\ScaffoldingInCode\ScaffoldingInCode\bin\Debug\netcoreapp3.1\ScaffoldingInCode.dll

Olusturma basarili oldu.
    0 Uyari
    0 Hata

Geçen Süre 00:00:00.97
PS C:\Users\dmt>
 
Not the dotnet build, command. The dotnet ef dbcontext scaffold command. Sorry, I should have been more explicit.
 

Latest posts

Back
Top Bottom