Skip to content

Ensure appsettings.{env}.json can be found - #8154

Open
patriksvensson wants to merge 1 commit into
mainfrom
patrik/seeder-fix
Open

Ensure appsettings.{env}.json can be found#8154
patriksvensson wants to merge 1 commit into
mainfrom
patrik/seeder-fix

Conversation

@patriksvensson

Copy link
Copy Markdown
Member

Currently, the ./Seed.json does not find the appsettings files due to the apps configuration base directory is set to ./dev. The appsettings files are also not copied to the output directory.

This PR makes sure that the files are copied to the output directory, and that the base directory for configuration is set to the binary's output directory.

🎟️ Tracking

No JIRA issue for this.

📔 Objective

Make the seeder usable for me again.

📸 Screenshots

N/A

Currently, the ./Seed.json does not find the appsettings files
due to the apps configuration base directory is set to `./dev`.
The appsettings files are also not copied to the output directory.

This PR makes sure that the files are copied to the output directory,
and that the base directory for configuration is set to the binary's
output directory.
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

This bugfix makes SeederUtility resolve its appsettings.{env}.json files relative to the build output directory instead of the process working directory, and adds the CopyToOutputDirectory items needed for those files to exist there. The change is consistent with how the seeder is actually launched — dev/seed.ps1 invokes dotnet run --project ../util/SeederUtility from dev/, so the previous Directory.GetCurrentDirectory() base path pointed at dev/. SeederUtility is the only non-Web-SDK project in the repo shipping appsettings*.json, so the explicit None Update items are required rather than redundant. No security, correctness, or breaking-change concerns found; configuration provider ordering is unchanged, so user secrets still take precedence over the checked-in development settings.

Code Review Details
  • 🎨 : AppContext.BaseDirectory resolves the same path without reflection or the null fallback, and matches the existing pattern in WebApplicationFactoryBase
    • util/SeederUtility/Configuration/GlobalSettingsFactory.cs:18

@patriksvensson patriksvensson added the t:bugfix Change Type - Bugfix label Aug 6, 2026
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.01%. Comparing base (b9f7a36) to head (73512d8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8154      +/-   ##
==========================================
- Coverage   67.48%   63.01%   -4.47%     
==========================================
  Files        2314     2314              
  Lines      100435   100435              
  Branches     9035     9035              
==========================================
- Hits        67774    63292    -4482     
- Misses      30381    34959    +4578     
+ Partials     2280     2184      -96     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Hinton
Hinton requested a review from theMickster August 6, 2026 12:56
Comment on lines +18 to +19
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
?? Directory.GetCurrentDirectory();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎨 SUGGESTED: AppContext.BaseDirectory resolves the same directory without reflection or a null fallback

Details and rationale
Suggested change
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
?? Directory.GetCurrentDirectory();
var directory = AppContext.BaseDirectory;

Assembly.GetExecutingAssembly().Location returns an empty string under single-file publish, so the ?? Directory.GetCurrentDirectory() branch silently falls back to the CWD-based behavior this PR is fixing. This project sets IncludeAllContentForSelfExtract, which suggests self-extract publishing is at least contemplated; AppContext.BaseDirectory points at the extraction/app directory in that mode and never returns null, so the fallback becomes unnecessary.

It also matches the existing pattern in the repo — see test/IntegrationTestCommon/Factories/WebApplicationFactoryBase.cs:183, which pairs SetBasePath(AppContext.BaseDirectory) for this same purpose.

@Hinton

Hinton commented Aug 7, 2026

Copy link
Copy Markdown
Member

We can lean into https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.host.createdefaultbuilder?view=net-11.0-pp and not manually load the appsettings files.

Current behavior of forcing everyone to manually set a connection string for table storage is not helpful.

@justindbaur justindbaur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this looking so much like Host.CreateDefaultBuilder() I sort of feel like that should be used instead. Since this is used to add it to services it doesn't feel to heavy handed and might be a good idea. I do think you'd still need the csproj changes though to make sure the appsettings files are in the output directory though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t:bugfix Change Type - Bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants