Open programm-ingovals opened 2 months ago
I ran into this as well - a couple potential solutions:
EF.IsDsignTime
is true
. This only works if you don't need the CLI flags to properly build the IHost
object or don't need the IHost
object for configuring the DbContext
(e.g., in a case where DbContext
configures itself independently of ASP.NET server build).using Microsoft.EntityFrameworkCore;
static void Main(string[] args)
{
if (EF.IsDesignTime)
{
Log.Logger.Here().Information("Design-time detected. Skipping server startup.");
return;
}
// Parse flags as normal, build ASP.NET application
}
applicationName
flag to CommandLineParser
to avoid the error and build the web app as normal.internal class Flags
{
#region ASP.NET Core Flags
[Option("applicationName", Default = "MyApp", HelpText = "The name of the application.")]
public string ApplicationName { get; set; }
// Other ASP.NET flags as-needed, e.g.:
[Option("environment", Default = "Production", HelpText = "The environment the application is running in.")]
public string Environment { get; set; }
#endregion
// Rest of flags...
}
I was trying to add CommandLineParser to a asp.net core project of mine to conditionally apply seed and test data on runs.
If I run any sort of tool on the assembly I get output from the Parser.
F.e.
dotnet ef migrations list
I'm assuming that the tools themselves are passing these options or something along the line. Everything seems to work properly, but is this something other people have dealt with in some way?