configuration name containing - (minus) are not set well as environment variable
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
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
>Add-Migration Test
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\.....\WebUI.Core\bin\Debug\net8.0\WebUI.Core.deps.json --additionalprobingpath C:\Users\...\.nuget\packages --runtimeconfig C:\.....\WebUI.Core\bin\Debug\net8.0\WebUI.Core.runtimeconfig.json C:\Users\...\.nuget\packages\microsoft.entityframeworkcore.tools\8.0.6\tools\netcoreapp2.0\any\ef.dll migrations add test --json --verbose --no-color --prefix-output --assembly C:\.....\WebUI.Core\bin\Debug\net8.0\WriteService.DataAccess.dll --project C:\.....\.WriteService.DataAccess\WriteService.DataAccess.csproj --startup-assembly C:\.....\WebUI.Core\bin\Debug\net8.0\WebUI.Core.dll --startup-project C:\.....\WebUI.Core\WebUI.Core.csproj --project-dir C:\.....\.WriteService.DataAccess\ --language C# **--configuration Development-Test** --working-dir C:\Repositories\...\src --root-namespace WriteService.DataAccess
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");
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{environmentName}.json")
.Build();
..........
}
}`
Thanks.
Contributor guide
Assessment
This issue has not been assessed yet.