Open mihaimarin83 opened 3 months ago
Have you tried enclosing the value in quotes, i.e. --configuration "Development-Test"
?
Have you tried enclosing the value in quotes, i.e.
--configuration "Development-Test"
?
This is not under my control. I just execute "Add-Migration Test" from the Package Manager Console
I have a configuration that has the name "Development-Test". I used this name since some years and never had problems until porting from ef6 to efcore.
The problem is that the environment variable contains the configuration name until the - (minus) sign.
configuration Development-Test => environment Development
Using assembly 'WriteService.DataAccess'. Using startup assembly 'WebUI.Core'. Using application base 'C:\Repositories...\src\WebUI.Core\bin\Debug\net8.0'. Using working directory 'C:\Repositories...\src\WebUI.Core'. Using root namespace 'WriteService.DataAccess'. Using project directory 'C:\Repositories...\src\WriteService.DataAccess\'. Remaining arguments: . Finding DbContext classes... Finding IDesignTimeDbContextFactory implementations... Finding application service provider in assembly 'WebUI.Core'... Finding Microsoft.Extensions.Hosting service provider... Using environment 'Development'. Using application service provider from Microsoft.Extensions.Hosting. Finding DbContext classes in the project... Found DbContext 'WriteModel'. Using DbContext factory 'MigrationsContextFactory'.
As you can see, we send "--configuration Development-Test " but is taken into account only 'Development'.
This is very unplesant because we need to read the connection string from the specific "appsetting.Development-Test.json" file in the DesignTimeDbContextFactory like:
`public class MigrationsContextFactory : IDesignTimeDbContextFactory
{
public WriteModel CreateDbContext(string[] args)
{
//ASPNETCORE_ENVIRONMENT is 'Development' instead of 'Development-Test'
var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
}`
Thanks.