Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unrecognized command or argument 'optimize' on Entity Framework Core .NET Command-line Tools 5.0.7 #25135

Closed
thangchung opened this issue Jun 22, 2021 · 6 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@thangchung
Copy link

I have found the blog post about EF on .NET Core 6 Preview 5 at https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-6-0-preview-5-compiled-models/

Then, I tried it on my laptop. I upgraded my EF Core CLI to the latest version as the guidance at https://docs.microsoft.com/en-gb/ef/core/cli/dotnet. But when I tried to run dotnet ef dbcontext optimize -c MyContext -o MyFolder -n My.Namespace. It threw the exception below

# dotnet ef dbcontext optimize -output-dir MyCompiledModels --namespace MyCompiledModels
Build started...
Build succeeded.
Specify --help for a list of available options and commands.
Unrecognized command or argument 'optimize'.

I wonder it might be has a nightly build for the EF tool for EF 6 preview 5, but not sure so that I posted the issue here.

My dev environment:

  • Windows 10
  • .NET SDK: 6.0.100-preview.5.21302.13
  • EF Core Tools: 5.0.7
  • Microsoft.EntityFrameworkCore: 6.0.0-preview.5.21301.9
  • Npgsql.EntityFrameworkCore.PostgreSQL: 6.0.0-preview4
  • Microsoft.EntityFrameworkCore.Design: 6.0.0-preview.5.21301.9
  • Microsoft.EntityFrameworkCore.Tools: 6.0.0-preview.5.21301.9
@ghost
Copy link

ghost commented Jun 22, 2021

Same here.

@chrarnoldus
Copy link

Update EF Core Tools to the preview version?

dotnet tool update --global dotnet-ef --version 6.0.0-preview.5.21301.9

@ghost
Copy link

ghost commented Jun 23, 2021

Yes, mine is similar to @thangchung:

Microsoft.EntityFrameworkCore.Design: 6.0.0-preview.5.21301.9
Microsoft.EntityFrameworkCore.SqlServer: 6.0.0-preview.5.21301.9
Microsoft.EntityFrameworkCore.Tools: 6.0.0-preview.5.21301.9
Microsoft.VisualStudio.Web.CodeGeneration.Design: 6.0.0-preview.5.21321.1
Swashbuckle.AspNetCore: 6.1.4

@AndriySvyryd AndriySvyryd added closed-no-further-action The issue is closed and no further action is planned. area-tools labels Jun 23, 2021
@thangchung
Copy link
Author

Thanks, @chrarnoldus. I could handle installing the newest tool and run Compiled Model sucessfully.

For those people who have got the issue just like me, I write down what I did as below

  • Install EF Core tools
$ dotnet tool update --global dotnet-ef --version 6.0.0-preview.5.21301.9
Tool 'dotnet-ef' was successfully updated from version '5.0.7' to version '6.0.0-preview.5.21301.9'.
  • Generate the compiled model
$ # stand at the root project which has the DbContext reside
$ dotnet ef dbcontext optimize -c MainDbContext -o CompiledModels -n ProductService.Infrastructure
Build started...
Build succeeded.
Connection String: Server=localhost;Port=5432;Database=postgres;User Id=postgres;Password=P@ssw0rd;
Server=localhost;Port=5432;Database=postgres;User Id=postgres;Password=P@ssw0rd;
Successfully generated a compiled model, to use it call 'options.UseModel(ProductService.Infrastructure.MainDbContextModel.Instance)'. Run this command again when the model is modified.
  • Register it
services.AddDbContext<MainDbContext>(options =>
{
    options.UseNpgsql(connString, sqlOptions =>
    {
        sqlOptions.MigrationsAssembly(typeof(MainDbContext).Assembly.GetName().Name);
        sqlOptions.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null);
    }).UseSnakeCaseNamingConvention();

    options.UseModel(ProductService.Infrastructure.MainDbContextModel.Instance); // this line of code is important
});

@matteo1010
Copy link

Hello,
check if you have a folder .config in the root project where in the file dotnet-tools.json is specify an older version in tools.dotnet-ef.version
I deleted the file an all work properly

@zahrazandi
Copy link

I had this problem, I set right project for Default Project in Package Manager Console so it Build succeeded

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

6 participants