基于环境的连接string与ASP NET CORE和Docker支持

我有一个ASP.NET核心应用程序与Docker的支持和下面的Startup.cs服务configuration:

  string connectionString = Environment.GetEnvironmentVariable("ORACLE_CONNECTION_STRING"); services.AddDbContext<BloggingContext>(options => options.UseOracle(connectionString)); 

我在docker-compose.override.yml设置了连接string:

 version: '2' services: continuouseverything: environment: - ASPNETCORE_ENVIRONMENT=Development - ORACLE_CONNECTION_STRING=Server=(DESCRIPTION = (ADDRESS = (PROTOCOL=TCP) (HOST=LOCALHOST) (PORT=1521)) (CONNECT_DATA= (SERVER=DEDICATED) (SERVICE_NAME=xe.oracle.docker))); direct=true; User Id=system; Password=oracle; Unicode=true ports: - "80" 

当我通过Docker启动应用程序时,我工作的很好。 在debugging器中,我可以看到connectionStringvariables得到了正确的连接string。

但是,当我尝试运行Add-Migration InitialCreate时,由于connectionStringvariables为null,因此在调用services.AddDbContext()时,Startup中出现ArgumentNullException

我怎样才能做到这一点, EnvironmentVariable的设置就像在docker-compose文件中定义的一样?

如果直接从Powershell运行Add-Migration InitialCreate ,则需要先在shell中设置环境variables。

$env:ORACLE_CONNECTION_STRING = "connstring goes here"; Add-Migration InitialCreate