Starts in:
0 DAY
15 HRS
52 MIN
25 SEC
Starts in:
0 D
15 H
52 M
25 S
Open Closed

Define appsettings file when run DbMigrator project through ASPNETCORE_ENVIRONMENT #2291


User avatar
0
christophe.baille created
  • ABP Framework version: v4.3.3
  • UI type: Angular / Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

In version 4.0.0, I wanted to run DbMigrator project with a different appsettings file depending if I was in dev, test or production. It is an angular solution

To make it work, I added a method BuildConfiguration on the class DbMigratorHostedService:

` private static IConfiguration BuildConfiguration() { var configurationBuilder = new ConfigurationBuilder();

        var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
        if (environmentName != null)
        {
            configurationBuilder.AddJsonFile($"appsettings.{environmentName}.json", true);
        }
        else
        {
            configurationBuilder.AddJsonFile("appsettings.json");
        }

        return configurationBuilder
            .AddEnvironmentVariables()
            .Build();
    }
}`

It was called with options.Services.ReplaceConfiguration(BuildConfiguration()); into AbpApplicationFactory.Create of StartAsync method, it was working well.

Even after updating this solution to ABP 5.0.0, I still do not have this issue.

I afterwards created another solution, using Blazor this time, with version 4.3.3, but I then get this error on the console:

D:\AppAI\src\AppAI.DbMigrator\bin\Debug\net6.0\AppAI.DbMigrator.exe (process 139992) exited with code -42. To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. Press any key to close this window . . .

I updated to ABP 5.0.0 as well, and I still get this issue.

Note: When creating a new solution with version 5.0.0, a DI is now used about IConfiguration options.Services.ReplaceConfiguration(_configuration); I tried to add it on my solution, but I do not see on how to change configuration values, I see production settings, but it's empty, even if I have a appsettings production file.


1 Answer(s)
  • User Avatar
    0
    christophe.baille created

    Just found why it was working on 4.0.0 and not 4.3.3, I simply forgot to setup the property "Copy to Output Directory" of the file as "Copy always".

    About IConfiguration, I do not know, but no need to use it yet...

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06