How to detect when project is run by Add-Migration

Viewed 160

I have a .net Core 3.1 Web API solution, using EF Core for the database. When I execute Add-Migration to generate database migrations, the tool runs the startup project. I want to skip some code that executes when the startup project starts (it will not impact the migration generation). Is there a way to tell, in the project code, that it has been launched from the EF tool?

1 Answers

While not completly reliable, a workarround could be to use #if DEBUG directive :

    public static void Main(string[] args)
    {
        #if DEBUG
        // Debug mode: stop here
        return;
        #endif

        // other stuff
    }
Related