Configure EF Core CLI Parameters

Viewed 199

I have an ASP.NET Core project with a data access layer using EF Core 3.1.8 and also using version 3.1.8 of the cli tools. The presentation layer and the data access layer are in different projects. To run EF commands in the cli, I open a developer command prompt, navigate to the directory containing the data access layer and run a command such as

dotnet ef migrations add MyMigrationName --startup-project ../Site/Site.csproj

or

dotnet ef database update --startup-project ../Site/Site.csproj

Site is just a placeholder here. The actual project name is longer and it is inconvenient to provide the --startup-project argument each time I want to run a command. Is there somewhere I can configure that so that I can run commands more concisely like dotnet ef database update?

1 Answers

Create a file named ef.cmd in the data access layer directory with the following contents:

@dotnet ef --startup-project ..\Site %*

Then you can use:

ef migrations add MyMigrationName

or

ef database update

For completeness, another option is to use response files. This isn't as simple, but can be useful when you have multiple sets of options. (e.g. for multiple DbContexts)

Create a file named something like identity.rsp with the following contents.

--startup-project=..\Site
--context=IdentityContext

And use it like this.

dotnet ef database update @identity.rsp
Related