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

Running dotnet-ef migrations bundle in a Azure pipeline #35157

Open
jepzen opened this issue Nov 20, 2024 · 3 comments
Open

Running dotnet-ef migrations bundle in a Azure pipeline #35157

jepzen opened this issue Nov 20, 2024 · 3 comments

Comments

@jepzen
Copy link

jepzen commented Nov 20, 2024

im running this command in my CI

dotnet-ef migrations bundle --output ./migrations-tool

But i get an error.

Unable to create a 'DbContext' of type ''. The exception 'No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

When I run it locally I notice that this command will connect to my database. Is that required to do this command ? If that is the reason i just dont really get the point of having this bundle command that is supposed to be CI friendly

https://devblogs.microsoft.com/dotnet/introducing-devops-friendly-ef-core-migration-bundles/

If a CI is dependent on a sql server is present

EF Core version: 8
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 8.0)
Operating system: MacOS
IDE: (e.g. Jet 2022 17.4)

@cincuranet
Copy link
Contributor

Based on the exception it looks like you haven't configured any provider for your 'DbContext`. However this issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

@jepzen
Copy link
Author

jepzen commented Nov 20, 2024

Yes ok I am not really allowed to to share my code but maybe I can clarify without. The migrations are located in the same project as the being the startup which is a WebApi with DI configured. Would it help to move migrations to another project like the Domain one? One that has not DI configured.

Or in other words. Can you run the dotnet-ef migrations bundle without having a Db connection?

@cincuranet
Copy link
Contributor

What's the working directory where you run the command? Could you try explicitly specifying --project <PROJECT> and/or --startup-project <PROJECT>?

For creating migrations bundle you don't need connection, but you need database provider configured (that's the Microsoft.EntityFrameworkCore.SqlServer for example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants