hanaim-devops / PriemChecker

0 stars 0 forks source link

De EF migrations add tool kan appsettings.json bestand niet vinden voor ConnectionString. #5

Open bartvanderwal opened 1 month ago

bartvanderwal commented 1 month ago

I get an error that on running the dotnet ef migrations add ... that - at design time - this EF tool cannot find the appsettings.json file:

Unable to create a 'DbContext' of type ''. The exception 'The configuration file 'appsettings.json' was not found and is not optional. The expected physical path was '/Users/bartvanderwal/Library/CloudStorage/OneDrive-HAN/MDO/PriemChecker/PriemCheckerLibrary/appsettings.json'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

I run it from the root PriemChecker' folder. The appsettings.json file is in the WebPriemChecker project (set as (EF) StartUp project). I have a Directory.Build.props file set like this:

<Project>
    <PropertyGroup>
        <EFMigrationsProject>PriemCheckerLibrary</EFMigrationsProject>
        <EFStartupProject>WebPriemChecker</EFStartupProject>
    </PropertyGroup>
</Project>

Do I need an extra setting for the Directory.Props.build file to specify the folder the settings file is in, besides the startupProject setting that is already there?

This used to work I think.

bartvanderwal commented 1 month ago

ChatGPT:

"It looks like the issue is that Directory.GetCurrentDirectory() is returning the path of the PriemCheckerLibrary project, and not the WebPriemChecker project where your appsettings.json file resides. To fix this, you need to explicitly tell Entity Framework Core to look in the WebPriemChecker project for the configuration files."

[...] Key Changes: SetBasePath is set to point to the WebPriemChecker project folder (../WebPriemChecker), where your appsettings.json file resides. The configuration now reads the correct settings file during design-time.