Ensure appsettings.{env}.json can be found - #8154
Conversation
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.
🤖 Bitwarden Claude Code ReviewOverall Assessment: APPROVE This bugfix makes Code Review Details
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
| var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) | ||
| ?? Directory.GetCurrentDirectory(); |
There was a problem hiding this comment.
🎨 SUGGESTED: AppContext.BaseDirectory resolves the same directory without reflection or a null fallback
Details and rationale
| 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.
|
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
left a comment
There was a problem hiding this comment.
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.
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